Live Validation – Cross Platform, Rails style validation on the client.

6 September 2007, 19:00, by Jon

I came across a great new validation library the other day which I wanted to share with you all. Live Validation by Alec Hill is a cross-platform client-side JavaScript validation framework which provides real-time feedback to the user as they type.

 

val2


val1

As I am currently reading the highly recommended Designing the Obvious: A Common Sense Approach to Web Application Design which discusses the use of Poka Yoke (Japanese for “mistake proofing”) devices on the web. One of which is the use of real-time validation to provide feedback to users as they make the error, rather than waiting to submit the form (which could extend beyond the screen) and finding that they cannot proceed. Sometimes searching for where they have made an error can be a challenge in itself! This client side validation library fits the bill nicely. Hoekman may argue that actually Alec is a little aggressive in his technique of pouncing on errors before the user has had a chance to get it right but I feel it is nice that the user can see as they type whether the field is valid.

Although this library seems clearly aimed at Rails developers (which I will elaborate on next) the library is fully cross platform/cross browser compatible, It has been tested across a large cross section of browsers on different platforms and can be used with any server side technology such as PHP, Ruby on Rails, ASP, Java, Python etc.

I mentioned the library is aimed at Rails developers and this is because the naming of validators for the JavaScript library closely match those built into the Rails Framework. There are the following validators build in:

  1. Presence
  2. Format (using Regular Expressions)
  3. Numericality
  4. Length
  5. Inclusion
  6. Exclusion
  7. Acceptance
  8. Confirmation
  9. Email

It is not clear if you can validate against a custom function, for example allowing you to create a AJAX request to the server to check Uniqueness of user names or email addresses on a registration form [I will contact Alec to clarify]. Validations can be combined together on a single field, so for example you can check if a field is required or not. Another nice feature is that you can check whether the whole form has validated, allowing you to prevent submission to the form as suggested by Alec, or use this to only enable the submit button once the form is valid as advocated by Hoekman.

Setting up validation on a field is easy, for example to Validate presence you would need the following code:

  1. var f1 = new LiveValidation(f1);
  2. f1.add( Validate.Presence );

The script is available as a standalone version or for integration with Prototype and is released under the MIT licence.

For more information see: livevalidation.com



Yay! the first comment.


I followed up my query regarding using a custom validator with Alec and have documented his response here.

Comment by Jon — 1 November 2007 @ 14:44

Leave a comment

About Jon

Jon started his career hacking code on his Sinclair Spectrum before moving on to more sophisticated machines ( ...such as a Commodore 64 ). He graduated from the University of Kent in 2000 with a degree in Computer Science and since then has worked in finance and education before co-founding Go Tripod. He is passionate about usability and design and his favourite development technologies are Ruby, and Objective-C/Cocoa. When he is not sat at his desk he is standing on his head doing yoga, refining his taste for food or on an adventure exploring the great outdoors.

Go Tripod Ltd

Go Tripod Ltd is a UK-based development company working with some of the most exciting software technologies around. Simon Ashley, Jon Baker and Colin Ramsay are the brains behind projects such as Stubmatic, and are developing bespoke web, mobile and desktop software for clients with household names. We believe in good service as well as good software, and we’re eager to work with people who feel the same.