Home > Web Front-end > JS Tutorial > body text

Jquery Validate regular expression practical validation code collection_jquery

WBOY
Release: 2016-05-16 17:24:35
Original
781 people have browsed it

Mobile phone number verification

The following is the quoted content:

Copy the code 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 == 11 && mobile.test(value));
}, "Mobile phone number format is wrong ");

Phone number verification

The following is the quoted content:

Copy code 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));
}, "Telephone number format Error");

Postcode verification

The following is the quoted content:

Copy code The code is as follows:

jQuery.validator. addMethod("zipCode", function(value, element) {
var tel = /^[0-9]{6}$/;
return this.optional(element) || (tel.test(value ));
}, "Postcode format error");

QQ number verification

The following is the quoted content:

Copy code 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 error");

IP address verification

The following is the quoted content:

Copy the code 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 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256));
}, "Ip address format error");

Verification of letters and numbers
The following is the quoted content:
Copy code 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 numbers and letters (characters A-Z, a-z, 0-9) can be entered");

Chinese verification

The following is the quoted content:

Copy the code The code is as follows:

jQuery.validator. addMethod("chinese", function(value, element) {
var chinese = /^[u4e00-u9fa5] $/;
return this.optional(element) || (chinese.test(value));
}, "Only Chinese can be entered");

Drop-down box verification

The following is the quoted content:

Copy code The code is as follows:

$.validator. addMethod("selectNone", function(value, element) {
return value == "Please select";
}, "Must select one");

Byte length verification

The following is the quoted content:

Copy the code 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("Please ensure that the entered value is between {0}-{1} bytes (a Chinese character Count 2 bytes)"));
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template