The benefits of form validation cannot be over emphasized. To end-users, they can often be an annoyance. To developers, webmasters and DBAs, they are pure preventative medicine (ok, so they taste as bas as Dr. Buckley’s, but they work!). Without them our databases would be full of empty and incorrect fields, and our applications constantly spewing out gross errors due to someone’s lack of form-filling motivation.
A tutorial for form validation can be found here. And this would suit a site well if all you have is one or two forms. But managing validation becomes a rather onerous task when you have a contact form, an event registration form, a sign in form, and so on and so forth.
Microsoft saw this coming, and they included a nice method of form validation within the .NET framework. The disadvantage there is that you’re still typing in validation code for each field in all of your forms. And what if you’re just not using .NET, what if you’re not even using any dynamic technology? Is there any easy way to validate all forms, once and for all?
Clearly this article wouldn’t exist were there not. So, I’m going to explain in gory detail two important and reusable methods: one for checking valid form data, the other for ensuring the proper data type is being entered.