Jquery Validate Default check rules and common custom validation rules

Source: Internet
Author: User
Tags valid email address

Jquery Validate related parameters and common custom validation rules

First, the official website address: http://bassistance.de/jquery-plugins/jquery-plugin-validation

Second, the default check rule

(1), Required:true               must lose field (2), Remote: "remote-valid.jsp"   using Ajax method call remote-valid.jsp Validation input value (3), Email:true                  Must enter the correct format of e-mail (4), Url:true                    must enter the correct format of the URL (5), Date:true                   must enter the correct format of the date, the date check IE6 error, with caution (6), Dateiso:true                You must enter the correct format for the date (ISO), for example: 2009-06-23, 1998/01/22 only verify the format, do not validate the validity (7), Number:true                 must enter a valid number (negative, decimal) (8), Digits:true                 Must enter an integer (9), Creditcard:true             must enter a valid credit card number (10), Equalto: "#password"        input value must be the same as #password (11), Accept:                    Enter a string with a valid suffix name (the suffix of the uploaded file) (12), a string with a                maximum input length of 5 (Kanji maxlength:5 one character) (13), and a string with a               minimum length of 10 for the Minlength:10 input (Chinese characters are counted as one character) (14), rangelength:[5,10]         The input length must be between 5 and 10 string ") (Chinese characters counted one character) (15), range:[5,10]               input values must be between 5 and 10 (16), Max:5                      Input value cannot be greater than 5 (17), Min:10                     input value cannot be less than 10

Third, the default hints

Messages: {required: ' This field is required. ', Remote: ' Please fix this field. ', email: ' Please enter a valid email address  . ", url:" Please enter a valid URL. ", Date:" Please enter a valid date. ", Dateiso:" Please enter a valid date (ISO). ", Datede: "Bitte geben Sie ein G Eyebrow Ltiges Datum ein.", Number: "Please enter a valid number.", Numberde: "Bitte geben Sie eine Nummer E In. ', digits: ' Please enter only digits ', CreditCard: ' Please enter a valid credit card number. ', Equalto: ' Please enter the Same value again. ", Accept:" Please enter a value with a valid extension. ", MaxLength: $.validator.format (" Please enter no M Ore than {0} characters. "), MinLength: $.validator.format (" Please enter at least {0} characters. "), Rangelength: $. Validator.format ("Please enter a value of between {0} and {1} characters long."), Range: $.validator.format ("Please enter a VA Lue between {0} and {1}. "), Max: $.validator.format (" Please enter a value of less than or equal to {0}. "), min: $.validator.for Mat ("Please enter a value greater than or equal to {0}. ")}, 

Iv. Jquery Validate Custom validation rules

Identification Number Verification
JQuery.validator.addMethod ("Idcardno", function (value, Element) {
return this.optional (Element) | | Isidcardno (value);
}, "Please enter your ID number correctly");

Alpha-Numeric
JQuery.validator.addMethod ("Alnum", function (value, Element) {
return this.optional (Element) | | /^[a-za-z0-9]+$/.test (value);
}, "can only include English letters and Numbers");

ZIP Code Verification
JQuery.validator.addMethod ("ZipCode", function (value, Element) {
var tel =/^[0-9]{6}$/;
return this.optional (Element) | | (Tel.test (value));
}, "Please fill in the ZIP code correctly");

Chinese characters
JQuery.validator.addMethod ("Chcharacter", function (value, Element) {
var tel =/^[u4e00-u9fa5]+$/;
return this.optional (Element) | | (Tel.test (value));
}, "Please enter Chinese characters");

Minimum character length verification (one Chinese character length is 2)
JQuery.validator.addMethod ("Stringminlength", function (value, element, param) {
var length = Value.length;
for (var i = 0; i < value.length; i++) {
if (Value.charcodeat (i) > 127) {
length++;
}
}
return this.optional (Element) | | (length >= param);
}, $.validator.format ("length cannot be less than {0}!"));

Character Maximum length verification (one Chinese characters length is 2)
JQuery.validator.addMethod ("Stringmaxlength", function (value, element, param) {
var length = Value.length;
for (var i = 0; i < value.length; i++) {
if (Value.charcodeat (i) > 127) {
length++;
}
}
return this.optional (Element) | | (length <= param);
}, $.validator.format ("length cannot be greater than {0}!"));

Character verification
JQuery.validator.addMethod ("string", function (value, Element) {
return this.optional (Element) | | /^[u0391-uffe5w]+$/.test (value);
}, "Do not allow special symbols!");

Mobile phone number Verification
JQuery.validator.addMethod ("mobile", function (value, Element) {
var length = Value.length;
return this.optional (Element) | | (length = = &&/^ ((13[0-9]{1}) | ( 15[0-9]{1})) +d{8}) $/.test (value));
}, "Phone number format is wrong!");

Phone number Verification
JQuery.validator.addMethod ("Phone", function (value, Element) {
var tel =/^ (d{3,4}-?)? d{7,9}$/g;
return this.optional (Element) | | (Tel.test (value));
}, "Phone number format is wrong!");

ZIP Code Verification
JQuery.validator.addMethod ("ZipCode", function (value, Element) {
var tel =/^[0-9]{6}$/;
return this.optional (Element) | | (Tel.test (value));
}, "bad postal code format!");

Must be validated at the beginning of a specific string
JQuery.validator.addMethod ("Begin", function (value, element, param) {
var begin = New RegExp ("^" + param);
return this.optional (Element) | | (Begin.test (value));
}, $.validator.format ("must start with {0}!"));

Verify that the two-time input values are not the same
JQuery.validator.addMethod ("Notequalto", function (value, element, param) {
return value! = $ (param). Val ();
}, $.validator.format ("two times input cannot be the same!"));

The validation value is not allowed with a specific value equal to
JQuery.validator.addMethod ("NotEqual", function (value, element, param) {
return value! = param;
}, $.validator.format ("input value not allowed for {0}!"));

The validation value must be greater than a specific value (cannot be equal)
JQuery.validator.addMethod ("GT", function (value, element, param) {
return value > param;
}, $.validator.format ("Input value must be greater than {0}!"));

Jquery Validate Default check rules and common custom validation rules

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.