Common regular validation

Source: Internet
Author: User

Mobile phone number Verification

The following is the reference content:

The code is as follows:
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));
}, "cell phone number format error");


Phone number Verification

The following is the reference content:

The code is as follows:
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));
}, "wrong phone number format");


ZIP Code Verification

The following is the reference content:

The code is as follows:
JQuery.validator.addMethod ("ZipCode", function (value, Element) {
var tel =/^[0-9]{6}$/;
return this.optional (Element) | | (Tel.test (value));
}, "Bad postal Code format");


QQ Number Verification

The following is the reference content:

The code is as follows:
JQuery.validator.addMethod ("QQ", function (value, Element) {
var tel =/^[1-9]\d{4,9}$/;
return this.optional (Element) | | (Tel.test (value));
}, "QQ number format is wrong");


IP Address Verification

The following is the reference content:

The code is as follows:
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 < Rege && regexp.$2 < regexp.$3, &&, < &&, and more.) Xp.$4 < 256));
}, "Malformed IP address");


Verification of letters and numbers
The following is the reference content:

The code is as follows:
JQuery.validator.addMethod ("Chrnum", function (value, Element) {
var chrnum =/^ ([a-za-z0-9]+) $/;
return this.optional (Element) | | (Chrnum.test (value));
}, "Only enter numbers and letters (characters A-Z, A-Z, 0-9)");


Verification of Chinese

The following is the reference content:

The code is as follows:
JQuery.validator.addMethod ("Chinese", function (value, Element) {
var Chinese =/^[\u4e00-\u9fa5]+$/;
return this.optional (Element) | | (Chinese.test (value));
}, "can only input Chinese");


Drop-down box validation

The following is the reference content:

The code is as follows:
$.validator.addmethod ("Selectnone", function (value, Element) {
return value = = "Please select";
}, "must select an item");


Byte length Verification

The following is the reference content:

The code is as follows:
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 text)");

Common regular validation

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.