If your goals is only validation then regex is your friend:
http://refiddle.com/refiddles/5cbef8db75622d10f36f0000
If you truly wish to prevent people from entering it, input masks is a good one, though users can go around that by being sneaky and changing your html. Thus you should always be validating again on the server side just to be sure.