0% found this document useful (0 votes)
466 views

Jquery Validator Cheat Sheet

This document summarizes the jQuery Validation plugin, which allows for validating form fields. It outlines how to initialize validation on a form with validate(), set validation rules, customize error messages, and use various callback functions and properties. It also lists validation methods, custom selectors, and common validation rule types like required, email, min, and max.

Uploaded by

sunjavasource
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
466 views

Jquery Validator Cheat Sheet

This document summarizes the jQuery Validation plugin, which allows for validating form fields. It outlines how to initialize validation on a form with validate(), set validation rules, customize error messages, and use various callback functions and properties. It also lists validation methods, custom selectors, and common validation rule types like required, email, min, and max.

Uploaded by

sunjavasource
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

JQuery Validator http://docs.jquery.

com/Plugins/Validation
$(form selector).validate(options);

Rules
$(“.selector”).validate({ minlength Numeric
rules: { maxlength Numeric
name: { required: true}, Rangelength Numeric, ex. rangelength: [2, 6]
email: { required: true, email: true } url True/false
date True/false
}
dateISO True/False
});
dateDE True/false (German Date)
required true/false phoneUS True/false
email true/false number True/false
digits True/false numberDE True/false (German Date)
creditcard True/false accept Ex: “xls|csv” (file types)
min Numeric equalTo(other) String, ex: “#password”
max Numeric remote String/options – see $.ajax for options

Messages
You can create special messages for each rule type.
$(“.selector”).validate({ rules: {…},
messages: {
name: “Please specify your name”,
email: { required: “Please enter your email address”, email: “Please enter a valid email address”}
}});

Validator Option callbacks


submitHandler(form) success(element)
invalidHandler(form, validator) highlight(element, errorClass)
errorPlacement(error, element) unhighlight(element)

Validator Option properties


debug: bool ignore: selector rules:{} messages:{}
groups: {} onsubmit: bool onfocusout: bool onkeyup:bool
onclick: bool focusInvalid: bool focusCleanup: bool Meta: string
errorClass: “error” validClass: “valid” errorElement: “label” wrapper: “li”
errorLabelContainer: errorContainer success:”valid” ignoreTitle: bool

Validator Plugin Methods


validate(options) valid() rules() rules(“add”, rules)
rules(“remove”, rules) removeAttrs(attr)

Validator Methods
form() element(element) addClassRules(name, Rules) showErrors(errors)
numberOfInvalids() resetForm() addMethod(name,method,message) setDetaults(defaults)

JQuery Custom Selectors:


:blank, :filled, :unchecked

You might also like