Plugin Information

Support development of this plugin by donation


jQuery Validator Plugin provides validation for user input in many different formats. This is a first public release of this plugin, so there are more features (such as additional and improved validation formats) coming in future versions.

Most of the validation formats are shown in demos above with the source code.

Supported Formats

  • Email
  • IP Address
  • Date
  • Date and Time
  • Phone
  • US Zip Code
  • Canada Zip Code
  • Credit Card
  • Numeric
  • Decimal
  • Alphanumeric

Usage

Validator PlugIn needs jQuery any 1.3.x version to operate correctly.
In addition, validator.js and validator.css files should be loaded in the header.

For validation to work, validator should be attached to each field that needs to be validated prior to that.
Below is the basic code to attach validator:

jQuery(function($){
	$('#field').validator();
});

After validator is attached, it will validate field on specific event (change and blur by default) or by calling validate method:

jQuery(function($){
	$('#field').validator('validate');
});
className
Type:
string
Default:
validator_error
Class name that will be applied to error elements.
trigger
Type:
string
Default:
change blur
List of event names that would trigger validation (separated by space).
format
Type:
string
Default:
null
Desired format of the field.

Supported formats:

Email
Key:
email
Example:
email@domain.com
IP Address
Key:
ip
Example:
111.111.111.111
Date
Key:
date
Example:
mm/dd/yyyy
mm-dd-yyyy
mm.dd.yyyy
mm dd yyyy
Date and Time
Key:
datetime
Example:
hh:mm
hh.mm
hh-mm
hh mm
date format is the same as above
Phone
Key:
phone
Example:
10-15 digits
0123456789
US Zip Code
Key:
zipUS
Example:
5 or 9 number formats
12345-0000
Canada Zip Code
Key:
zipCanada
Example:
A6A 6A6
Credit Card
Key:
creditCard
Example:
just generic digits and 13-16 characters length validation without CRC verification for now
Numeric
Key:
numeric
Example:
digits only
Decimal
Key:
decimal
Example:
1,000.04
commas allowed for currency
Alphanumeric
Key:
alphanumeric
Example:
allowed: digits, any letters (international character supported) case insensitive, space, hyphen (-), underscore (_), and dot (.).
invalidEmpty
Type:
boolean
Default:
false
If set to true - element is invalid when empty.
minLength
Type:
integer
Default:
null
Minimum length of characters for the element to stay valid.
maxLength
Type:
integer
Default:
null
Maximum length of characters for the element to stay valid.
minValue
Type:
number
Default:
null
Minimum number value for the element (for number inputs only).
maxValue
Type:
number
Default:
null
Maximum number value for the element (for number inputs only).
contains
Type:
string, regexp
Default:
null
Text which element should contain to be valid.
notContains
Type:
string, regexp
Default:
null
Text which element should NOT contain to be valid.
equals
Type:
string
Default:
null
If it is set, element value should equal to this parameter to be valid.
notEquals
Type:
string
Default:
null
If it is set, element value should NOT equal to this parameter to be valid.
checked
Type:
boolean
Default:
null
True - checkbox should be checked, false - checkbox should be unchecked.
validate
This methods validates a given field. Validator should be setup on this field prior to call of this function.
before
Arguments:
field, value
Return:
string
This event is triggered right before validation. Return value (string) will be used for validation.

this equals to field element that is used in validation.

Arguments:
  • field: field element that is used in validation
  • value: value of the field
after
Arguments:
field, value, error
Return:
string
This event is triggered right after validation. Return value (boolean) will be used for error notification regardless the validation result itself.
Any changes to error object will affect error notification that follows this function call.

this equals to field element that is used in validation.

Arguments:
  • field: field element that is used in validation
  • value: value of the field
  • error: object with 3 parameters: boolean status, string type, string message
error
Arguments:
field, value, error
Return:
boolean
This event is triggered on error after validation. If return value (boolean) is false, default error notification will not be used.

this equals to field element that is used in validation.

Arguments:
  • field: field element that is used in validation
  • value: value of the field
  • error: object with 3 parameters: boolean status, string type, string message
correct
Arguments:
field, value
Return:
boolean
This event is triggered on correct after validation. If return value (boolean) is false, default correct notification (none, if no error notification was shown before) will not be used.

this equals to field element that is used in validation.

Arguments:
  • field: field element that is used in validation
  • value: value of the field
Download
Version: 0.1.3 (release notes)

jquery-validator-0.1.3.zip
minified and uncompressed files
size: 6kb

Version 0.1.3

  • Added support for international characters in alphanumeric validation format
  • Following characters added into alphanumeric validation format: space, hyphen (-), underscore (_), and dot (.).

Version 0.1

  • The first public release.
Contact and Support
In case of any questions, comments, or feature requests you can contact me directly at:

igor [DOT] gladkov [AT] gmail [DOT] com

or

just go to the project page.


Support forum will be installed in near future.
this.author = " Igor Gladkov ";
this.contact = " igor [dot] gladkov [at] gmail [dot] com ";