Validatious 2.0

Easy form validation with unobtrusive JavaScript

Getting started

If you want to add validators programmatically, check out features on the core API and DSL API. For validation through markup, read on!

Include script

Download and include the script, preferably just before the closing body tag:

Mark forms for validation

Default behaviour is for Validatious to validate all your forms with the class name validate:

Add validators

Adding validators is as simple as adding validator names as class names to input/select/textarea elements:

<input type="text" name="email" id="email" class="required email" />

Reasonable default error messages

Validatious guesses field names from label elements to make default error messages more usable:


...yields "Name is required". So does this:


Custom error messages

You can override all error messages for a single field through the input/select/textarea elements title attribute:


Scope validation

If your form has more than one button you may want some of your buttons (cancel and so on) not to trigger validation. Well, just add the class "action" to the buttons that should trigger validation:


Validate fields together in a group

Require atleast one field in a group to be valid by grouping fields in a div or fieldset with the class name "validate_any" (entering one valid phone number is sufficient for these three fields to pass validation):

Validate radio buttons

You can add validators to a set of radio buttons by adding class names to only one element in the group:

Validate checkboxes

Checkboxes can be validated just like radio buttons, however, they need to be explicitly grouped first, by giving all input elements a class name like g_:

Change validation timing

Validatious will validate your form when a submit button is clicked. When the form has been validated, Validatious will revalidate each field when they change. You can make Validatious validate each field whenever they change all the time:

v2.Field.prototype.instant = true;

...or only validate on submit:

v2.Field.prototype.instantWhenValidated = false;
v2.Field.prototype.instant = false;

Styling errors

By default, Validatious will display all messages (one per validator/field combination that fails) above the failing field:

  • Name is required

More on displaying error messages

Tutorials and reference

There are more detailed guides in the features section. The reference section contains lists of all things Validatious, and is a great place to start if you're looking to tweak/change a specific feature.

All features.

© 2008 Christian Johansen. Validatious is licensed with a BSD License, documentation and site content with CC Attribution-Share Alike. About.