1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148-149 150 151 152 153 154 155 156 157 158 159 160 161 162-163 |
var idcardnoutil = { Provinceandcitys: {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: "Macao", 91: "Foreign"}, Powers: ["7", "9", "Ten", "5", "8", "4", "2", "1", "" 6 "," 3 "," 7 "," 9 "," Ten "," 5 "," 8 "," 4 "," 2 "], paritybit: [" 1 "," 0 "," X "," 9 "," 8 ", "7", "6", "5", "4", "3", "2"], genders: {male: "male", Female: "Female"}, Checkaddresscode:function (Addresscode) {var check =/^[1-9] D{5}$/.test (Addresscode); if (!check) return false; if (Idcardnoutil.provinceandcitys[parseint (addresscode.substring (0,2))] {return true;} else{return False}}, Checkbirthdaycode:function (Birdaycode) {var check =/^[1-9]d{3} ((0[1-9)) | ( 1[0-2])) ((0[1-9]) | ( [1-2] [0-9]) | (3[0-1]) $/.test (Birdaycode); if (!check) return false; var yyyy = parseint (birdaycode.substring (0,4), 10); var mm = parseint (birdaycode.substring (4,6), 10); var dd = PArseint (birdaycode.substring (6), 10); var xdata = new Date (YYYY,MM-1,DD); if (XData > New Date ()) {return false;//birthday cannot be greater than the current date}else if ((xdata.getfullyear () = = yyyy) && (Xdata.getmont H () = = mm-1) && (xdata.getdate () = = dd) {return true;} else{return false;}, Getparitybit:function (Idcardno) {var id17 = idcardno.substring (0,17); var power = 0; var i=0;i<17;i++) {Power + + parseint (Id17.charat (i),) * parseint (Idcardnoutil.powers[i]);} var mod = power% 11; return Idcardnoutil.paritybit[mod]; }, Checkparitybit:function (Idcardno) {var paritybit = Idcardno.charat. toUpperCase (); if ( Idcardnoutil.getparitybit (idcardno) = = Paritybit) {return true;} else{return false;}, Checkidcardno:function (Idcardno) {//15-bit and 18-bit identity card number Basic checksum var check =/^d{15}| ( D{17} (d|x| X)) $/.test (Idcardno); if (!check) return false; Determine whether the length is 15-bit or 18-bit if (idcardno.length==15) {return Idcardnoutil.check15idcardno (Idcardno);} else if (idcardno.length==18) {return IdcardnouTil.check18idcardno (Idcardno); }else{return False}, //verify 15-bit ID number check15idcardno:function (idcardno) {//15-bit ID number for basic check var check =/^[1-9]d{7 } ((0[1-9]) | (1[0-2]) ((0[1-9]) | ([1-2][0-9]) | (3[0-1]) D{3}$/.test (Idcardno); if (!check) return false; Verify address code var Addresscode = idcardno.substring (0,6); Check = Idcardnoutil.checkaddresscode (Addresscode); if (!check) return false; var birdaycode = ' n ' + idcardno.substring (6,12); Check Date code return Idcardnoutil.checkbirthdaycode (Birdaycode); //Verify 18-bit ID number check18idcardno:function (idcardno) {//18-bit ID number basic format check var check =/^[1-9]d{5}[1-9]d{3} ((0[1-9) )| (1[0-2]) ((0[1-9]) | ([1-2][0-9]) | (3[0-1]) D{3} (d|x| X) $/.test (Idcardno); if (!check) return false; Verify address code var Addresscode = idcardno.substring (0,6); Check = Idcardnoutil.checkaddresscode (Addresscode); if (!check) return false; Check Date code var birdaycode = idcardno.substring (6,14); Check = Idcardnoutil.checkbirthdaycode (Birdaycode); if (!check) return false; Verify School Check code return Idcardnoutil.checkpariTybit (Idcardno); }, Formatedatecn:function (day) {var yyyy =day.substring (0,4); var mm = day.substring (4,6); var dd = day.substring ( 6); return yyyy + '-' + mm + '-' + dd; //Get information Getidcardinfo:function (Idcardno) {var idcardinfo = {gender: "",//Sex Birthday: ""//Birth date (YYYY-MM-DD)}; if (idcardno.length==15) {var aday = ' n ' + idcardno.substring (6,12); IDCARDINFO.BIRTHDAY=IDCARDNOUTIL.FORMATEDATECN ( Aday); if (parseint (Idcardno.charat)%2==0) {Idcardinfo.gender=idcardnoutil.genders.female;} else{Idcardinfo.gender=idcardnoutil.genders.male}} else if (idcardno.length==18) {var aday = idcardno.substring (6,14); IDCARDINFO.BIRTHDAY=IDCARDNOUTIL.FORMATEDATECN ( Aday); if (parseint (Idcardno.charat)%2==0) {Idcardinfo.gender=idcardnoutil.genders.female;} else{Idcardinfo.gender=idcardnoutil.genders.male} } return idcardinfo; }, Getid15:function (Idcardno) {if (idcardno.length==15) {return idcardno;} else if (idcardno.length==18) {return idcardno.substring (0,6) + Idcardno.SUBSTRING (8,17); }else{return null;}, Getid18:function (Idcardno) {if (idcardno.length==15) {var id17 = idcardno.substring (0,6) + ' 19 ' + Idcardno.substring (6); var paritybit = idcardnoutil.getparitybit (ID17); return id17 + paritybit; }else if (idcardno.length==18) {return idcardno;} else{return null;} }; Verify that the Passport is correct function checknumber (number) {var str=number;//in JavaScript, regular expressions can only use the "/" Start and end, and cannot use double quotes var expression=/(Pd {7}) | (gd{8})/; var objexp=new RegExp (Expression); if (Objexp.test (str) ==true) {return true;} else{return false;}; |