You can enable the client-side git hooks available on a per repo basis at .git/hooks. Inside this subdirectory you may find a bunch of samples. Here's a description of the hooks and how to use them.
In this case I think that the most suitable hook is commit-msg and you can check if the file that holds the proposed commit log message contains a susbtring in the form #123. For that purpose you could use the following regular expression:
$(grep '^.*#([1-9][0-9]*).*$' $1)