<script type= "Text/javascript" >/** Mobile Phone number format * Only allow numbers starting with 13, 15, 18 * For example: 13012345678, 15929224344, 18201234676*/varregmobile=/^1[3,5,8]\d{9}$/;/** Fixed telephone number format * Because the fixed phone format is more complex, the situation is more, mainly verify the following types of * such as: 010-12345678, 0912-1234567, (010)-12345678, (0912) 1234567, (010) 12345678, (0912)-1234567, 01012345678, 09121234567*/varregphone=/^ (^0\d{2}-?\d{8}$) | (^0\d{3}-?\d{7}$) | (^0\d2-?\d{8}$) | (^0\d3-?\d{7}$) $/;/** Email address * such as: [email protected], [email protected], [email protected]*/varregemail=/^ ([a-za-z0-9]+[_|\-|\.]?) *[a-za-z0-9][email protected] ([a-za-z0-9]+[_|\-|\.]?) *[a-za-z0-9]+ (\.[ a-za-z]{2,3}) +$/;/** ID card 15-bit encoding rules: DDDDDD YYMMDD xx p * Dddddd:6 region code * YYMMDD: Year of birth (two years) month day, such as: 910215 * XX: Sequential encoding, System generation, unable to determine * p: gender, odd male, even female * * ID card 18-bit encoding rules: dddddd yyyymmdd xxx y * dddddd:6 region code * YYYYMMDD: Year of birth (four years) month day, such as: 19910215 * XXX: Sequential encoding, System generation, cannot be determined, odd for male, even for female * y : Check code, this bit value can be calculated by the first 17 digits * * The first 17 digits weighted factor for Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] * Verify bit Y = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2] * If the verification code is exactly 10, in order to ensure that the ID is 18, then the 18th bit will use X instead of the * check digit calculation formula: y_p = mod (∑ (AIXWI), one) * I for ID card number 1 ... 17 bits; Y_p is the location of the check code array where the checksum y is located*/functionValidateidcard (idcard) {//Regular expressions for 15-bit and 18-bit ID numbers varregidcard=/^ (^[1-9]\d{7} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{3}$) | (^[1-9]\d{5}[1-9]\d{3} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) ((\d{4}) |\d{3}[xx]) $) $/; //If you pass this verification, the ID card is in the correct format, but the accuracy needs to be calculated if(Regidcard.test (Idcard)) {if(idcard.length==18){ varIdcardwi=NewArray (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);//Save the first 17-bit weighting factor in an array varidcardy=NewArray (1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2);//This is the 11-bit remainder, the verification code, which is divided by 11, which can also be saved as an array varidcardwisum=0;//used to hold the sum of the first 17 digits after the weighted factor. for(vari=0;i<17;i++) {idcardwisum+=idcard.substring (i,i+1) *Idcardwi[i]; } varidcardmod=idcardwisum%11;//calculates the position of the array where the checksum is located varIdcardlast=idcard.substring (17);//get the last ID number . //if it equals 2, then the check code is 10, the last digit of the ID number should be x if(idcardmod==2){ if(idcardlast== "X" | | idcardlast== "X") {alert ("Congratulations passed the verification!" "); }Else{alert ("Wrong ID number!" "); } }Else{ //use the calculated verification code to match the last identity card number, if the same, the explanation passed, otherwise it is invalid ID number if(idcardlast==Idcardy[idcardmod]) {Alert ("Congratulations passed the verification!" "); }Else{alert ("Wrong ID number!" "); } } } }Else{alert ("ID card format is incorrect!"); }}/** can only be a positive integer*/varregnum=/^\d+$/;/** ZIP Code*/varregpostcode=/^\d{6}$/;/** User name * can only be alphanumeric underline, and start with a letter (5-16 bit)*/varregusername=/^[a-za-z]\w{4,15}$/;/** IP address * such as: 192.168.1.102*/varregip=/^ (([1-9]\d?) | (1\d{2}) | (2[0-4]\d) | (25[0-5])) \.) {3} ([1-9]\d?) | (1\d{2}) | (2[0-4]\d) | (25[0-5])) $/;/** can only be Chinese characters*/varregchinesechar=/^[\u4e00-\u9fa5]+$/;/** URL * Only allow HTTP, HTTPS, FTP these three kinds of * such as: http://www.baidu.com*/varregweb=/^ ([Hh][tt]{2}[pp][ss]?) | ([ff][tt][pp])) \:\/\/[ww]{3}\. [\w-]+\.\w{2,4} (\/.*)? $/;/** Date Format verification * Because the date format is more, the main validation of the following types * 2012-05-14, 2012/05/6, 2012.5.14, 20120528*/varRegdate=/^[1-9]\d{3} ([-|\/|\.])? ((0\d) | ([1-9]) | (1[0-2])) \1 (([0|1|2]\d) | ( [1-9]) | 3[0-1]) $/;/** Call the above regular expression method * To verify the phone number format as an example*/functionOnCheck (tel) {if(Regmobile.test (tel)) {Alert ("Congratulations passed the verification!" "); }Else{alert ("Not properly formatted!" "); }}</script>
Regular Expressions _ Common regular validation