var idcardnoutil = { * * Province, the Central Municipality code table * * 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: "Macau", 91: "Abroad"}, /* per-weighting factor * * Powers: ["7", "9", "10", "" 5 "," 8 "," 4 "," 2 "," 1 "," 6 "," 3 "," 7 "," 9 "," 10 "," 5 "," 8 "," 4 "," 2 "],
/* 18th School Inspection Code * * Paritybit: ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"], * * Sex * Genders: {male: "male", Female: "Female"}, /* Verify Address code * * 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; } }, /* Check Date code * *
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.getmonth () = = mm-1) && (xdata.getdate () = = dd) ){
return true;
}else{
return false;
}
},
/* Calculate the School Check code * *
Getparitybit:function (Idcardno) {
var id17 = idcardno.substring (0,17);
/* Weighted *
var power = 0;
for (Var i=0;i<17;i++) {
Power + + parseint (Id17.charat (i), ten) * parseint (idcardnoutil.powers[i));
}
/* Take die/*
var mod = power% 11;
return Idcardnoutil.paritybit[mod];
},
/* Verify the School check code * *
Checkparitybit:function (Idcardno) {
var paritybit = Idcardno.charat. toUpperCase ();
if (idcardnoutil.getparitybit (idcardno) = = Paritybit) {
return true;
}else{
return false;
}
}, /* Verify 15-bit or 18-bit ID number */ checkidcardno:function (idcardno) { // Basic checksum for 15-bit and 18-bit ID numbers var check =/^d{15}| ( D{17} (d|x| X)) $/.test (Idcardno); if (!check) return false; //Judgment length 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 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; //Checksum address code var addresscode = idcardno.substring (0,6); Check = Idcardnoutil.checkaddresscode (Addresscode); if (!check) return false; var birdaycode = ' n ' + idcardno.substring (6,12); //Checksum date code return Idcardnoutil.checkbirthdaycode (birdaycode ); }, //verify 18-bit ID number check18idcardno:function (idcardno) { // Basic format verification for 18-bit ID number 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; //Checksum address code var addresscode = idcardno.substring (0,6); check = Idcardnoutil.checkaddresscode (Addresscode); if (!check) return false; //Checksum date code var birdaycode = idcardno.substring (6,14); check = Idcardnoutil.checkbirthdaycode (Birdaycode); if (!check) return false; //Verifying 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: "",//gender
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 (14))%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 (16))%2==0) {
Idcardinfo.gender=idcardnoutil.genders.female;
}else{
Idcardinfo.gender=idcardnoutil.genders.male;
}
}
return idcardinfo;
},
/*18 15-bit * *
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;
}
},
/*15 18-bit * *
Getid18:function (Idcardno) {
if (idcardno.length==15) {
var id17 = idcardno.substring (0,6) + ' + ' + idcardno.substring (6);
var paritybit = idcardnoutil.getparitybit (ID17);
return id17 + paritybit;
}else if (idcardno.length==18) {
return idcardno;
}else{
return null;
}
}
}; ID Card number Verification JQuery.validator.addMethod ("Idcardno", function (value, Element) { return this.optional (Element) | | Idcardnoutil.checkidcardno (value); "Please specify a valid ID number."); Get ID Information var idcardinfo = Idcardnoutil.getidcardinfo (Idcardno); Alert (Idcardinfo.gender + "|" + Idcardinfo.birthday); |