Jquery.validate use strategy Fifth step validation _jquery

Source: Internet
Author: User
Tags zip
Mobile phone number Verification
JQuery.validator.addMethod ("mobile", function (value, Element) {
var length = Value.length;
var mobile =/^ ((13[0-9]{1}) | ( 15[0-9]{1}) +\d{8}) $/
return this.optional (Element) | | (length = = && Mobile.test (value));
}, "mobile phone number format error");

Phone number Verification
JQuery.validator.addMethod ("Phone", function (value, Element) {
var tel =/^ (0[0-9]{2,3}\-)? ([2-9][0-9]{6,7}) + (\-[0-9]{1,4})? $/;
return this.optional (Element) | | (Tel.test (value));
}, "Phone number format error");

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

QQ Number Verification
JQuery.validator.addMethod ("QQ", function (value, Element) {
var tel =/^[1-9]\d{4,9}$/;
return this.optional (Element) | | (Tel.test (value));
}, "QQ number format error");

IP Address Verification
JQuery.validator.addMethod ("IP", function (value, Element) {
var ip =/^ (?:(? : 25[0-5]|2[0-4][0-9]| [01]? [0-9] [0-9]?) \.) {3} (?: 25[0-5]|2[0-4][0-9]| [01]? [0-9] [0-9]?) $/;
return this.optional (Element) | | (Ip.test (value) && (Regexp.$1 < 256 && regexp.$2 < 256 && regexp.$3 < 256 && Rege Xp.$4 < 256));
}, "IP address format error");

Verification of letters and numbers
JQuery.validator.addMethod ("Chrnum", function (value, Element) {
var chrnum =/^ ([a-za-z0-9]+) $/;
return this.optional (Element) | | (Chrnum.test (value));
"Only numbers and letters (characters A-Z, A-Z, 0-9)" can be entered;

Verification in Chinese
JQuery.validator.addMethod ("Chinese", function (value, Element) {
var Chinese =/^[\u4e00-\u9fa5]+$/;
return this.optional (Element) | | (Chinese.test (value));
"Can only be entered in Chinese");

Dropdown box Validation
$.validator.addmethod ("Selectnone", function (value, Element) {
return value = = "Please select";
"Must select an item");

byte length validation
JQuery.validator.addMethod ("Byterangelength", 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[0] && length <= param[1]);
$.validator.format ("Make sure the value entered is between {0}-{1} bytes (2 bytes in one)");

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.