Validatious 2.0

Easy form validation with unobtrusive JavaScript

Creating compound validation logic

The HTML extension has the ability to validate a set of fields as a group, and choose if they are "and" or "or" validations. With the core API and the DSL extension, you can create arbitrary compound rules like these, and you can involve the same field in several rules.

You create compound rules with and and or, which work pretty much like validate/validateAll and validateAny: They accept any number of validation rules (either single fields or nested and/or rules), and upon validation, and (like validateAll) requires all its arguments to pass validation, and or (like validateAny) requires atleast one of its arguments to pass.

validate(
  "name".is("required"),
  "email".is("required").andIsAn("email"),
  or(
    "home_phone".is("required").andIsA("phone"),
    "office_phone".is("required").andIsA("phone"),
    "cell_phone".is("required").andIsA("phone")
  )
);

Visibility

Note that Validatious has the built-in ability to skip validation for hidden fields if you so require. There's no need to create complicated logic to achieve this kind of conditional validation.

Error reporting

The default error reporting extension only provides a display of error messages for fields and fieldsets. The and and or methods does not create fieldset objects, so when using these to create compund validations, you also need to create some error display for them.

Back to DSL features index

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