jQuery Valideasy

Never write complex JS script again to handle your form validation rules! With Valideasy, everything's done via HTML attributes added to your form fields.

Get on Github

No JS Required

Specify how a field should validate by simply adding classes and html attributes to it. No complicated JavaScript code to configure basic validation rules.

Custom Errors

Valideasy allows you to completly customize how error messages should be displayed. And again, everything's done with simple html attributes!

Cross Browser

Valideasy is compatible with all modern browsers, starting from IE7.

For most forms, you won't need extra configuration for Valideasy to work properly. In some cases though, you might need to change the default parameters to meet your specific needs. There are two ways to set parameters:

Let's take an example with the mode parameter (described below), you can set it either in your form element:

<form data-valideasy-mode="unified">

Or when instantiating the plugin:

$(this).valideasy({
  mode: 'unified'
});

Here is the full (but short) list of available parameters, along with their default values. To use them as data- attributes, simply prefix with data-valideasy-

Note Parameters expecting functions cannot be used as data- attributes.

defaults = {
  mode: 'single',
  errorElementId: 'errors',
  disableFieldStyle: false,
  stepByStep: false,
  scrollToFirstError: false,
  singleFieldValidation: false,
  onValidateBefore: function() { return; },
  onValidateAfter: function() { return; },
}

mode

How error messages are displayed.

errorElementId

Indicates the ID of the field(s) supposed to display error messages.

disableFieldStyle

Set to true to stop adding the .error class to fields with errors

stepByStep

Set to true to stop validation at first error

scrollToFirstError

Set to true to auto scroll to the first error field at the end of the validation process

singleFieldValidation

Set to true to only perform validation on one field, instead of on the entire form.
For this to work, Valideasy must be instantiated on a field element.

Hooks

As of version 2.2.1, you can hook to pre and post validation events to perform certain tasks. Available hooks are :

<form novalidate action="/" method="post">

  <input class="{rules}" id="name" title="Name" type="text" value="Name" />
  <p id="name_errors" class="error-wrapper"></p>

</form>

Required

Example

Valid!

Important For this rule to work, the default value or option MUST be placed in the title attribute.

Email

Example

Valid!

Telephone

Accepts spaces, dashes and points

Example

Valid!

Number

Accepts spaces, dashes and points

Example

Valid!

Integer

Only digit.

Example

Valid!

URL

Example

Valid!

Zipcode

Example

Valid!

Password Verification

Example


Valid!

At least one field required

Allows to specifiy that, in a set of fields, at least one is required. All of the fields in the set must have the same data-error-grouprequired attribute.

The data-error-fieldid attribute is used to specify in which element the error message should be inserted.

Example

Valid!

Values comparison : lower than ou greater than

Allows to specify that the value of the field must be lower or greater than the value of another field. To indicate the other field, use the data-error-{lowerthan or greaterthan} attribute.

The data-error-lowerthan attribute is used to specify in which element the error message should be inserted.

Example

Valid!

Error Handling

When a field fails at validating a rule, the .error class is added to it, and will be remove on the next click on the field.

Default Error Messages

Each validation rule comes with a default error message:

Customize Error Messages

Two ways to customize error messages :

Example

Valid!

Example

Valid!

Advanced Examples

Combined Rules

At least one field required + "Minimum Price" must be lower than "Maximum Price".

Example

Valid!

Unified Errors

Only one spot for error messages.

Example

Valid!

Stop at first error

The validation process stops when the first error occurs.

Example

Valid!

Post Validation Hook

Example

Valid!


Note Open console to take a look at parameters passed to the function

Single Field Validation + Live Validation

Example

Valid!