Form Validation

Javascript can be used to validate forms; however after implementing an re-implementing a number of variations on the theme I decided to produce a standard library which could be used anywhere.

The idea was to use the principles of unobtrusive javascript to develop a generic form validation method which would require as little configuration as possible to validate the most common HTML forms.

As usul on this site, I will show the results before I describe how it works, therefore, below is a form which implements my validation script.


     
    

Configuration

In order to configure the form for validation, each field requiring validation must be given one or more classes. The classes and their meanings are detailed below.

In addition to setting the class of the form elements, the only other requirement is that each element must have a label assocated with it. This is used in any validation messages shown to the user.

Last updated: 12 Mar 2008 20:15:56