I know I've been posting a lot on forms and validation recently, however we should all agree on the fact that
form validation is really a serious problem for programmers.
When a user submit data to our database, the first thing we should consider is to protect the destination. Our database is waiting for specific data and, for example, a text string must not be submitted to a smalldate field.
On the other hand, we should provide a complete and efficient way to help the user in filling in the form. Specifically in commercial situations, if we want the visitors to conclude painlessly a commercial transaction, we should make things the easiest possible way for him/her.
When we check what the user is submitting, we can be sure that the birth date or the credit card expiration date is truly a valid date - for the user protection and security and for the web site owner who needs to be sure that everything works smoothly.
In the following example, we are going to validate emails, however, by changing the regular expression, we can check almost anything.
In the following example we use
RegEx in a short
JavaScript function.