Recently, we need to use Form Verification for user registration information, and then I checked some information. I will share with you some of the frequently used JS form verification functions that I hope will be useful to you.
Recently, we need to use Form Verification for user registration information, and then we have checked some information. I will share with you some of the frequently used JS form verification functions that I hope will be useful to you.
// Email Verification
1 // email verification 2 // returns true after verification; otherwise, false 3 function isEmail (emailStr) {4 if (emailStr. length = 0) {5 return fasle; 6} else {7 var emailPat =/^ (. + )@(. +) $/; 8 var specialChars = "/(/) <> @,;:///"/. /[/] "; 9 var validChars =" [^/s "+ specialChars +"] "; 10 var quotedUser =" ("[^"] * ")"; 11 var ipDomainPat =/^ (d {1, 3}) [.] (d {1, 3}) [.] (d {1, 3}) [.] (d {1, 3}) $/; 12 var atom = validChars + '; 13 var word = "(" + atom + "|" + qu OtedUser + ")"; 14 var userPat = new RegExp ("^" + word + "(/. "+ word +") * $ "); 15 var domainPat = new RegExp (" ^ "+ atom + "(/. "+ atom +") * $ "); 16 var matchArray = emailStr. match (emailPat); 17 if (matchArray = null) {18 return false; 19} 20 var user = matchArray [1]; 21 var domain = matchArray [2]; 22 if (user. match (userPat) = null) {23 return false; 24} 25 var IPArray = domain. match (ipDomainPat); 26 If (IPArray! = Null) {27 for (var I = 1; I <= 4; I ++) {28 if (IPArray [I]> 255) {29 return false; 30} 31} 32 return true; 33} 34 var domainArray = domain. match (domainPat); 35 if (domainArray = null) {36 return false; 37} 38 var atomPat = new RegExp (atom, "g"); 39 var domArr = domain. match (atomPat); 40 var len = domArr. length; 41 if (domArr [domArr. length-1]. length <2) | 42 (domArr [domArr. length-1]. length> 3) {43 return false; 44} 45 if (len <2) {46 return false; 47} 48 return true; 49} 50} 51
/// IP address verification
// Return true to the correct IP address; otherwise, false is returned.
function isIp(strIp) { var ipDomainPat=/^((2[0-4]d|25[0-5]|[01]?dd?).){3}(2[0-4]d|25[0-5]|[01]?dd?)$/; var matchArray=strIp.match(ipDomainPat); if(matchArray!=null){ return true; } }
// Phone number verification
// If the phone number is correct (including the area code and "-" such as 0571-1234567 [8] 010-1234567 [8]), true is returned. Otherwise, false is returned.
function isTelphoneNum(telNum){ var telphoneNumPat=/^0d{2}-d{7,8}|0d{3}-d{7,8}$/; var matchArray=telNum.match(telphoneNumPat); if(matchArray!=null){ return true; } }
// Mobile phone number verification
// If the phone number is correct (for example, 13800571506 013800571505), true is returned. Otherwise, false is returned.
function isMobilephoneNum(mobileNum){ var mobilephoneNumPat=/^1d{10}|01d{10}$/; var matchArray=mobileNum.match(mobilephoneNumPat); if(matchArray!=null){ return true; } }
// Enter a pure number to verify the input. If the input is a pure number, true is returned. Otherwise, false is returned.
function isDigital(str){ var digitalPot=/^d*$/; var matchArray=str.match(digitalPot); if(matchArray!=null){ return true; } }
// 18-digit ID card verification. If you enter the correct number, true is returned. Otherwise, false is returned.
function card(id){ var Wi=new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1); var ai="10X98765432"; var sum=0 var ssum=0; for(var i=0;i<17;i++){ ssum=eval(Wi[i]*id.charAt(i)); sum=ssum+sum; } var modNum=sum%11; if(ai.charAt(modNum)==id.charAt(17)){ return true; } }