Generic Form Validation Routine
Generic Form Validation Routine is yet another useful, unobtrusive, progressive enhancement ECMAScript technique from Gez Lemon. No inline scripts to be seen.
- Previous post: Ten questions for Tommy Olsson
- Next post: Keeping pretties out of content
Information, sponsorship, and externals
About the author
Roger Johansson is a Swedish web professional specialising in web standards, accessibility, and usability. More about me and this site.
Latest articles
- Validation statistics from Nikita the Spider Comments off
- An analysis of the sites crawled by the bulk validation tool Nikita the Spider during March 2008.
- Authentic Jobs API and Affiliates program Comments off
- The Authentic Jobs job listing service now has a public API and an affiliate program.
- What does Acid3 mean to you and me? Comments off
- Opera and Apple have announced that their web browsers pass the Acid3 Browser Test, but how will that help web designers and developers?
- Designing Web Navigation (Book review) Comments off
- Learn the fundamentals of navigation design and design better navigation systems for large and small sites as well as for web based applications.
- DOMAssistant bundle for TextMate Comments off
- To save keystrokes and speed up development I have created a DOMAssistant bundle for TextMate.
- First impressions of Internet Explorer 8 Beta 1 Comments off
- My impressions after trying out Internet Explorer 8 Beta 1 for a couple of days.









Comments
Here's another example of this I made some time ago. The classname of the elements determines the regular expression used for validation.
Offcourse, validation should also always be done server side to make sure.
className based regexp form validation
I prefer having an extra field (suprisingly called "validation") that holds all of the validation information for the form. The field should be a disabled and hidden input, which the ECMAScript can access to give an instant response to anything going wrong.
I tend not to like popups, so my versions also creates an error message in a at the top of the page. Meanwhile, the invalid fields are also highlighted in red (with a .invalid class name).
Good technique.
We all learned in ASP.NET that client-side validation is icing on the cake; while server-side validation is a must.
At my previous job about 50% of all errors occured because some developers never bothered to check length and integrity of data they were storing in the database.
The link is currently returning 503 (Service Unavailable).
That Juicy Studio site is down quite frequently. You get to learn that from ASP.NET too :)
Yeah I've noticed intermittent problems with accessing the site. It usually only lasts a minute or so.
Quite a nice method. I started toying with a naming convention for fields with validation strings e.g. INTfieldname. When data got passed back my PHP it knew what to validate without having to hardwire each form. I guess it'd also work in JavaScript too but the field names are a bit messy :)
I don't usually mess with client side validation but when it's nice and easy you may as well!
Um, that link to Juicy Studio is now a 404 error. It's only a month since this blog entry? Does the web realy move this fast?
Juicy Studio has been having hosting problems and was forced to move to a new domain and host. That probably explains the 404 error. Hopefully it is only temporary.
Sorry, comments are closed for this post.