The best way to achieve this is probably through javascript as it checks it before the form is sent. If you
google you should find something that fits the bill. (Though you should note that if the user has scripting switched off in the browser then it will not work...)