This article has sorted out all the related to the JavaScript form verification, we must read it carefully.
Verify that the string is non-null var Validator = {veritylib: {isnotempty:function (input) {if (Input!= ') {
return true;
else {return false; },//Validation number (double type) [can contain minus and decimal points] isnumber:function (input) {var regex =/^-?\d+$|^ (-?\d+) (\.\d+)?
$/;
if (Input.match (regex)) {return true;
else {return false;
},//verify integer isinteger:function (input) {var regex =/^-?\d+$/;
if (Input.match (regex)) {return true;
else {return false;
},//verify nonnegative integer isintegernotnagtive:function (input) {var regex =/^\d+$/;
if (Input.match (regex)) {return true;
else {return false;
},//Verify positive integer isintegerpositive:function (input) {var regex =/^[0-9]*[1-9][0-9]*$/;
if (Input.match (regex)) {return true;
else {return false; }
},//Verify decimal isdecimal:function (input) {var regex =/^ ([-+]?[
1-9]\d*\.\d+|-?0\.\d*[1-9]\d*) $/;
if (Input.match (regex)) {return true;
else {return false;
},//validation contains only the English letter isenglishcharacter:function (input) {var regex =/^[a-za-z]+$/;
if (Input.match (regex)) {return true;
else {return false;
},//validation contains only numbers and English letter isintegerandenglishcharacter:function (input) {var regex =/^[0-9a-za-z]+$/;
if (Input.match (regex)) {return true;
else {return false;
},//validation contains only kanji ischinesecharacter:function (input) {var regex =/^[\u4e00-\u9fa5]+$/;
if (Input.match (regex)) {return true;
else {return false; },//Verify the digital length range (0-meter length of the digital front end) [to verify the fixed length, you can pass in the same two-length values] isintegerlength:function (input, Lengthbegin, lengthend) {var pattern =' ^\\d{' + lengthbegin + ', ' + lengthend + '}$ ';
var regex = new RegExp (pattern);
if (Input.match (regex)) {return true;
else {return false;
},//validation string contains content isstringinclude:function (input, Withenglishcharacter, Withnumber, Withchinesecharacter) { if (! Boolean (withenglishcharacter) &&! Boolean (withnumber) &&!
Boolean (Withchinesecharacter)) {return false;///If there are no English letters, numbers, and kanji, returns false} var pattern = ' ^[';
if (Boolean (withenglishcharacter)) {pattern = = ' a-za-z ';
} if (Boolean (withnumber)) {pattern = = ' 0-9 ';
} if (Boolean (withchinesecharacter)) {pattern = = ' \\u4E00-\\u9FA5 ';
Pattern = = ']+$ ';
var regex = new RegExp (pattern);
if (Input.match (regex)) {return true;
else {return false; },//Verify string length range [to verify a fixed length, you can pass in the same two-length values] Isstringlength:fuNction (input, Lengthbegin, lengthend) {var pattern = ' ^.{' + lengthbegin + ', ' + lengthend + '}$ ';
var regex = new RegExp (pattern);
if (Input.match (regex)) {return true;
else {return false; },//Verify string length range (contains only numbers and/or English letters within a string) [to verify the fixed length, you can pass in the same two-length values] isstringlengthonlynumberandenglishcharacter:funct
Ion (Input, Lengthbegin, lengthend) {var pattern = ' ^[0-9a-za-z]{' + lengthbegin + ', ' + lengthend + '}$ ';
var regex = new RegExp (pattern);
if (Input.match (regex)) {return true;
else {return false; },//Verify string length range [to verify the fixed length, you can pass in the same two-length values] isstringlengthbyinclude:function (input, withenglishcharacter, wit Hnumber, Withchinesecharacter, Lengthbegin, lengthend) {if (!withenglishcharacter &&!withnumber &&
!withchinesecharacter) {return false;///If there are no English letters, numbers, and kanji, returns false} var pattern = ' ^['; if (BooleA (withenglishcharacter)) pattern = = ' a-za-z ';
if (Boolean (withnumber)) pattern = = ' 0-9 ';
if (Boolean (withchinesecharacter)) pattern = = ' \\u4E00-\\u9FA5 ';
Pattern = + ']{' + lengthbegin + ', ' + lengthend + '}$ ';
var regex = new RegExp (pattern);
if (Input.match (regex)) {return true;
else {return false; },//verify string bytes length range [to verify the fixed length, you can pass in the same two-length values; each Chinese character is two bytes long] isstringbytelength:function (input, Lengthbegin, Len
Gthend) {var regex =/[^\x00-\xff]/g;
var bytelength = input.replace (regex, ' OK '). length;
if (bytelength >= lengthbegin && bytelength <= lengthend) {return true;
else {return false; },//validation date [can only validate date, cannot validate time] isdatetime:function (input) {if (Date.parse (input)) {return T
Rue
else {return false; },//Verify fixed phone number [3-bit or 4-bit area code; Area code can be enclosed in parentheses; area codeCan be omitted, the area code and the local number can be separated by a minus sign or a space, can have 3-digit extension number, the extension number before the minus sign] istelephonenumber:function (input) {var regex =/^ ((0\d2|0\d{2} )[- ]?)? \d{8}| ((0\d3|0\d{3}) [-]?
\D{7}) (-\d{3})? $/;
if (Input.match (regex)) {return true;
else {return false;
},//Verify mobile phone number [can be matched "(+86) 013325656352", parentheses can be omitted, + can be omitted, (+86) can be omitted, 11-digit mobile phone number before 0 can be omitted; the second digit of 11 digits can be any of 3, 4, 5, 8. Ismobilephonenumber:function (input) {var regex =/^ (\+)? 86| ( (\+)? 86)
0?1[3458]\d{9}$/;
if (Input.match (regex)) {return true;
else {return false; },//Verify the phone number (can be a fixed phone number or mobile number) Isphonenumber:function (input) {var regex =/^ (\+)? 86| ( (\+)? 86) 0?1[3458]\d{9}$|^ ((0\d2|0\d{2}) [-]? \d{8}| ((0\d3|0\d{3}) [-]?
\D{7}) (-\d{3})? $/;
if (Input.match (regex)) {return true;
else {return false; },//Verify that the ZIP code iszipcode:function (input) {var regex =/^\d{6}$/;
if (Input.match (regex)) {return true;
else {return false; },//Verify that e-mail can contain letters before the @ character, numbers, underscores, and dots; The @ character can contain letters, numbers, underscores, and dots, and the @ character contains at least one point number and the point number cannot be the last character; only the last point is a letter or number. Isema Il:function (Input) {////mailbox name begins with a number or letter; The mailbox name can be composed of letters, numbers, dots, minus signs and underscores; the mailbox name (the character before @) is 3~18 characters; the mailbox name cannot end with a dot, a minus sign, or an underscore; you cannot have two or more two consecutive
Point number, minus sign. var regex =/^[a-za-z0-9] ((? <! ( \.\.| -) [a-za-z0-9\._-]) {1,16}[a-za-z0-9]@ ([0-9a-za-z][0-9a-za-z-]{0,62}\.) + ([0-9a-za-z][0-9a-za-z-]{0,62}) \.?| ((25[0-5]|2[0-4]\d| [01]?\d\d?] \.) {3} (25[0-5]|2[0-4]\d| [01]?\d\d?]
$/; var regex =/^ ([\w-\.] +) @ ([\w-\.] +)(\.
[a-za-z0-9]+) $/;
if (Input.match (regex)) {return true;
else {return false; },//Verify the URL (can match the IPV4 address but not the IPV4 address for format verification; IPv6 does not make a match for the time being (allow omitting "://"; You can add port numbers; Allow hierarchies; allow arguments; at least one point in a domain name and before this point) Isurl: function (input) {////Each domain name consists of letters, numbers, and minus signs (the first letter cannot be a minus sign), case-insensitive, a single field length of not more than 63, complete domain name length of not more than 256 characters. In a DNS system, the full name is a point "." To end, for example, "www.nit.edu.cn." NoThe last point represents a relative address. No prefix for example "http://", no matching//var regex =/^ ([0-9a-za-z][0-9a-za-z-]{0,62}\.) + ([0-9a-za-z][0-9a-za-z-]{0,62}) \.?
$/; var regex =/^ ((FILE|GOPHER|NEWS|NNTP|TELNET|HTTP|FTP|HTTPS|FTPS|SFTP)://) | ( www\.)) + ([a-za-z0-9\._-]+\. [A-za-z] {2,6}) | ([0-9]{1,3}\. [0-9] {1,3}\. [0-9] {1,3}\. [0-9] {1,3}))
(/[a-za-z0-9\&%_\./-~-]*) $/; var regex =/^ ([a-za-z]+:\/\/)? ([\w-\.] +)(\. [a-za-z0-9]+) (: \d{0,5})? \/? ([\w-\/]*) \.? ([a-za-z]*) \?? (([\w-]*=[\w%]*&??)
*)$/;
if (Input.match (regex)) {return true;
else {return false; },//Verify that the IPV4 address [first and last digits cannot be 0 or 255; Allow 0 complement] isipv4:function (input) {var regex =/^ (25[0-4]|2[0 -4]\d]| [01]?\d{2}| [1-9]) \. (25[0-5]|2[0-4]\d]| [01]?\d?\d) \. (25[0-5]|2[0-4]\d]| [01]?\d?\d) \. (25[0-4]|2[0-4]\d]| [01]?\d{2}| [1-9])
$/;
if (Input.match (regex)) {return true;
else {return false; },//verify IPV6 address [can be used to match any valid IPV6 address]
Isipv6:function (input) {var regex =/^\s* (([0-9a-fa-f]{1,4}:) {7} ([0-9a-fa-f]{1,4}|:)) | ([0-9a-fa-f]{1,4}:) {6} (: [0-9a-fa-f]{1,4}| ( (25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d) (\. ( 25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d)) ({3}) |:)) | ([0-9a-fa-f]{1,4}:) {5} ((: [0-9a-fa-f]{1,4}) {1,2}) |:( (25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d) (\. ( 25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d)) ({3}) |:)) | ([0-9a-fa-f]{1,4}:) {4} ((: [0-9a-fa-f]{1,4}) {1,3}) | ( (: [0-9a-fa-f]{1,4})?:( (25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d) (\. ( 25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d)) ({3})] | ([0-9a-fa-f]{1,4}:) {3} ((: [0-9a-fa-f]{1,4}) {1,4}) | ( (: [0-9a-fa-f]{1,4}) {0,2}:((25[0-5]|2[0-4]\d|1\d\d|[ 1-9]?\d) (\. ( 25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d)) ({3})] | ([0-9a-fa-f]{1,4}:) {2} ((: [0-9a-fa-f]{1,4}) {1,5}) | ( (: [0-9a-fa-f]{1,4}) {0,3}:((25[0-5]|2[0-4]\d|1\d\d|[ 1-9]?\d) (\. ( 25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d)) ({3})] | ([0-9a-fa-f]{1,4}:) {1} ((: [0-9a-fa-f]{1,4}) {1,6}) | ( (: [0-9a-fa-f]{1,4}) {0,4}:((25[0-5]|2[0-4]\d|1\d\d|[ 1-9]?\d) (\. ( 25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d)) ({3})] | (:((: [0-9a-fa-f]{1,4}) {1,7}) | ((: [0-9a-fa-f]{1,4}) {0,5}:((25[0-5]|2[0-4]\d|1\d\d|[ 1-9]?\d) (\. ( 25[0-5]|2[0-4]\d|1\d\d| [1-9]?\d)) ({3}))] (:)))
(%.+) \s*$/;
if (Input.match (regex)) {return true;
else {return false;
},//verify ID number [verifiable generation or second-generation ID] isidcard:function (input) {input = Input.touppercase (); Verify the ID card number format [number of 15 digits for a generation of ID card number; the second generation ID number is 18 digits or 17 digits plus the letter X] if (! /(^\d{15}$) | (^\d{17} ([0-9]|
X) $)/i.test (input)) {return false; }//Verify province var arrcity = {11: ' Beijing ', 12: ' Tianjin ', 13: ' Hebei ', 14: ' Shanxi ', 15: ' Inner Mongolia ', 21: ' Liaoning ', 22: ' Jilin ', 23: ' Heilongjiang ', 31: ' Shanghai ', 32: ' Jiangsu ', 33: ' Zhejiang ', 34: ' Anhui ', 35: ' Fujian ', 36: ' Jiangxi ', 37: ' Shandong ', 41: ' Henan ', 42: ' Hubei ', 43: ' Hunan ', 44: ' Guangdong ', 45: ' Guangxi ', 46 : ' Hainan ', 50: ' Chongqing ', 51: ' Sichuan ', 52: ' Guizhou ', 53: ' Yunnan ', 54: ' Tibet ', 61: ' Shaanxi ', 62: ' Gansu ', 63: ' Qinghai ', 64: ' Ningxia ', 65: ' Xinjiang ', 71: ' Taiwan ', 81:
' Hong Kong ', 82: ' Macau ', 91: ' Abroad '};
if (Arrcity[parseint (input.substr (0, 2))] = = null) {return false; }//VerifyDate of birth Var Regbirth, Birthsplit, birth;
var len = input.length;
if (len = =) {Regbirth = new RegExp (/^ (\d{6}) (\d{2}) (\d{2}) \d{2);
Birthsplit = Input.match (Regbirth);
Birth = new Date (' n ' + birthsplit[2] + '/' + birthsplit[3] + '/' + birthsplit[4]); if (!) ( Birth.getyear () = = number (birthsplit[2]) && (Birth.getmonth () + 1) = = number (birthsplit[3)) &&
Birth.getdate () = = number (Birthsplit[4])) {return false;
return true; The else if (len = =) {Regbirth = new RegExp (/^ (\d{6}) (\d{4}) (\d{2}) (\d{2}) (\d{3}) ([0-9]|
X) $/i);
Birthsplit = Input.match (Regbirth);
Birth = new Date (birthsplit[2] + '/' + birthsplit[3] + '/' + birthsplit[4]); if (!) ( Birth.getfullyear () = = number (birthsplit[2]) && (Birth.getmonth () + 1) = = number (birthsplit[3)) && birth
. getDate () = = number (Birthsplit[4])) {return false; //Verify the checksum code var Valnum;
var arrint = new Array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
var arrch = new Array (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 ');
var ntemp = 0, I;
for (i = 0; i < i++) {ntemp + = Input.substr (i, 1) * arrint[i];
} valnum = arrch[ntemp% 11];
if (Valnum!= input.substr (1)) {return false;
return true;
return false; },//Verify longitude islongitude:function (input) {var regex =/^[-\+]? (
(1[0-7]\d{1}|0?\d{1,2}) \.\d{1,5}|180\.0{1,5}) $/;
if (Input.match (regex)) {return true;
else {return false; },//verify latitude islatitude:function (input) {var regex =/^[-\+]? (
[0-8]?\d{1}\.\d{1,5}|90\.0{1,5}) $/;
if (Input.match (regex)) {return true;
else {return false;
}
}
}
}
This collation is very comprehensive, very detailed, hope can really help everyone. It's more helpful to have a good command of JavaScript.