The ramblings of Chad Humphries

Client side validation for the rest of us

Notice: I am a Castle Project PMC member and committer.

After doing applications in Ruby in Rails and MonoRail I’ve come to appreciate the need for a simple, client-side validation script to complement the excellent validation both provide by their respective ActiveRecord implementations.

MonoRail includes fValidate which works pretty well, but is no longer actively maintained outside of the Castle team.

In the past few days I’ve started using the prototype validation based framework from Dexagogo. While there are features that wForms or fValidate have initially that this doesn’t, I believe the trade-off for having such a solid cross browser base (prototype) is well worth it.

Excerpt from the article:

So here it is in it’s first usable, albeit basic, form.

Include the javascript libraries:

<script src="prototype.js" type="text/javascript"></script>
<script src="validation.js" type="text/javascript"></script>

You write elements like this:

<input class="required validate-number" id="field1" name="field1" />

passing the validation requirements in the class attribute.

You then activate validation by passing the form’s id attribute like this:

<script type="text/javascript">
  new Validation('form-id');

It has a number of tests built-in but is extensible to include your custom validation checks.

Read the full article for more detail.


Written by spicycode

May 20, 2006 at 5:46 pm

Posted in programming

Tagged with ,

%d bloggers like this: