guards.js

View the Project on GitHub on-site/guards.js

Data Attributes

Guarding the form

Since version 1.3.0, you can specify your guards via data attributes alone. This will use any named guards that exist (including custom named guards). Currently, grouped guards (like oneRequired) are not supported. On your form, specify it to be guarded by adding the data-guarded attribute to enable guards, or the data-live-guarded attribute to enable live guards.


required

Guard options

You can specify multiple guards delimited by spaces, and you can provide arguments to those guards. Arguments that are not of a single options object form are not supported (such as passing an array for allow or a regex for regex). However, as of version 1.3.1, all built in named guards that required something other than a single options object now support an object form as well.


required and int >= 3

Further customizing the guard

The data attributes also supports changing the message of a specific type of named guard. Simply add a data-guard-<type>-message to either the parent form or the element itself. The <type> is the name of the guard (such as required or int). If specified on the form, it overrides the message for that named guard on any applicable element of that form. If specified on the element, it only applies to that element (and it will override any message specified at the form level).

int


required and int >= 3


required


required

previous next