VM UI Framework provides form validation for almost every type of form element with over 20
unique validators, plus the ability to create your own using regular expressions. The form
validation is live and is activated on either the blur
event for individual form
elements or on the submit
event for the form. If a field validates, it will turn green,
with either the default or a customized success message.
Each form element must have a unique id. Validations are added to a field using the
data attribute data-validate
, which takes a JSON object as a value. The JSON object
should have the validator names as keys. Each key should have the value of another object, with two
possible keys: error
and params
.
Each validator has a default error, which you can override with your own error message. However, if
you want to use the default error message, simply omit the error
key.
Some validators will need you to pass in parameters in order to function. For those validators, the
params
key is required. If the validator doesn't require parameters, omit the
params
key. You will need to pay special attention to what type of parameter value is
required for each validator as they vary.
If you want to use the default error message and the validator doesn't have parameters, simply pass in an empty object as the value for the validator key.
If you would like to pass in a custom message to displayed on successful validation, use the
data-success
attribute. Since there is only one success message per form field, the
value of data-success
is simply a string.
Validator Name | Description | Required Parameters |
---|---|---|
required |
Makes the field required. | None |
regex |
A custom regular expression to be evaluted. Note If you
use regex , be sure to pass in a custom error message as the default
message won't be very helpful to users. |
regex string regex |
minLength |
Enforces a minimum length on the input value. | integer minValue |
maxLength |
Enforces a maximum length on the input value. | integer maxValue |
range |
Enforces a both a minimum and a maximum length on the input value. | array [minValue , maxValue ] |
matches |
The field value must match the value of the field name passed in as a parameter. Useful for password matching fields. | string matchName |
differs |
The opposite of matches . Ensures two fields do not have the same value. |
string differName |
includes |
The field must contain one of the passed in values. | array [value1 , value2 , ...] |
excludes |
The field cannot contain one of the passed in values. | array [value1 , value2 , ...] |
alpha |
Only alphabetic character are accepted. | None |
numeric |
Only numeric character are accepted. | None |
alphanumeric |
Only alphanumeric character are accepted. | None |
email |
Requires a valid email address. | None |
url |
Requires a valid URL. | None |
password |
Password must contain one lowercase letter, one uppercase letter, one number, and be at least 6 characters long. | None |
usZip |
Validates US ZIP codes. | None |
canadaPostal |
Validates Canadian postal codes. | None |
credit |
Validates all major credit cards. | None |
dateMDY |
Tests a date for a M/D/Y format. | None |
dateYMD |
Tests a date for a Y/M/D format. | None |
imageFile |
For use with file inputs. Tests to see if the selected file is an image. | None |
phone |
Validates North American phone number formats. | None |
VM UI Framework is created, owned, maintained by Virtuosi Media, Inc. © 2012-2013.