Universal Form Validation
(Page 1 of 5 )
We have witnessed the wonders of JavaScript and its ability to ensure that our forms are properly filled before submission. But it gets so laborious to type and modify and update form validation scripts for every for in every application. Take heart! Upon reading and applying the methods in this article, you will never again have to worry about client-side validation! Hazzah!
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.
To respond to our pleas, many websites have posted many articles, examples, and ‘cut & paste’ scripts that we can slap onto a form to have it scrutinize a user’s every move. Thanks to JavaScript, forms can become somewhat more reliable within our applications.
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.
Next: First, the Forms >>
More JavaScript Articles
More By Justin Cook