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.

Posted on April 27, 2005 in JavaScript, Quicklinks, Usability


  1. 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

  2. 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).

  3. 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.

  4. The link is currently returning 503 (Service Unavailable).

  5. That Juicy Studio site is down quite frequently. You get to learn that from ASP.NET too :)

  6. April 29, 2005 by Roger Johansson (Author comment)

    Yeah I’ve noticed intermittent problems with accessing the site. It usually only lasts a minute or so.

  7. 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!

  8. 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?

  9. May 24, 2005 by Roger Johansson (Author comment)

    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.

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.