Formvalidator is a jQuery plugin that performs basic field validation based on html attributes. When called on an element containing data fields (such as a form element) the plugin traverses to the data fields and returns a collection of invalid fields.
The plugin uses several html data attributes to perform its validation: 'data-vrule', 'data-vminval', 'data-vmaxval', 'data-vregex', and 'data-verror'. The first attribute, 'data-vrule', sets the validation rule to be applied to the element. If 'data-vrule' is not present the field is ignored and assumed valid. The next three attributes are optional parameters used in various validation rules as described below.
The last attribute, 'data-verror', is set by the plugin on each element that is returned by the plugin and contains a message describing the validation error.
The validation rule for the field is set using the 'data-vrule' attribute. The following rules are supported:
notempty | The field cannot be empty |
minlength | field has a minimum length specified in 'data-vminval' |
maxlength | field has a maximum length specified in 'data-vmaxval' |
lenbetween | field must have a length between the values in 'data-vminval' and 'data-vmaxval' inclusive |
valbetween | field must have a value between the values in 'data-vminval' and 'data-vmaxval' inclusive |
isnumeric | field must be a valid number (float or integer) |
isalpha | field only contains the letters a-z |
isalphanumeric | field only contains the letters a-z and numbers 0-9 |
isemail | field appears to be a valid email address |
matchregex | field matches the regular expression given in 'data-vregex' |