function checkIdcard(idcard){
var Errors=new Array(
"Verification passed!",
"The number of ID card numbers is wrong!",
"The date of birth of the ID card number is out of range or contains illegal characters!",
"Identity card number verification error!",
"Identity card area is illegal!"
);
var area={11:"Beijing",12:"Tianjin",13:"Hebei",14:"Shanxi",15:"Inner *",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:"*",71:"*",81:"*",82:"Macao",91:"Foreign"}
var idcard,Y,JYM;
var S,M;
var idcard_array = new Array();
idcard_array = ("");
//Regional Inspection
if(area[parseInt((0,2))]==null) return Errors[4];
alert(Errors[4]);
//Check the number of digits and formats of the identity number
switch(){
case 15:
if ( (parseInt((6,2))+1900) % 4 == 0 || ((parseInt((6,2))+1900) % 100 == 0 && (parseInt((6,2))+1900) % 4 == 0 )){
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//Test the legality of the date of birth
} else {
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//Test the legality of the date of birth
}
if((idcard)) return Errors[0];
alert(Errors[0]);
else return Errors[2];
alert(Errors[2]);
break;
case 18:
//18-digit identity number detection
//The legality check of the date of birth
//Leap year Month and Date: ((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
//Previous year, month and day: ((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
if ( parseInt((6,4)) % 4 == 0 || (parseInt((6,4)) % 100 == 0 && parseInt((6,4))%4 == 0 )){
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//Legality regular expression for dates of birth in leap years
} else {
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//The legality regular expression of the date of birth in the ordinary year is the regular expression of the date of birth.
}
if((idcard)){//Test the legality of the date of birth
// Calculate the check bit
S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
+ parseInt(idcard_array[7]) * 1
+ parseInt(idcard_array[8]) * 6
+ parseInt(idcard_array[9]) * 3 ;
Y = S % 11;
M = "F";
JYM = "10X98765432";
M = (Y,1);//Judge the check bit
if(M == idcard_array[17]) return Errors[0]; //Check bit of the detection ID
else return Errors[3];
alert(Errors[3]);
}
else return Errors[2];
alert(Errors[2]);
break;
default:
return Errors[1];
alert(Errors[1]);
break;
}
}
var Errors=new Array(
"Verification passed!",
"The number of ID card numbers is wrong!",
"The date of birth of the ID card number is out of range or contains illegal characters!",
"Identity card number verification error!",
"Identity card area is illegal!"
);
var area={11:"Beijing",12:"Tianjin",13:"Hebei",14:"Shanxi",15:"Inner *",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:"*",71:"*",81:"*",82:"Macao",91:"Foreign"}
var idcard,Y,JYM;
var S,M;
var idcard_array = new Array();
idcard_array = ("");
//Regional Inspection
if(area[parseInt((0,2))]==null) return Errors[4];
alert(Errors[4]);
//Check the number of digits and formats of the identity number
switch(){
case 15:
if ( (parseInt((6,2))+1900) % 4 == 0 || ((parseInt((6,2))+1900) % 100 == 0 && (parseInt((6,2))+1900) % 4 == 0 )){
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//Test the legality of the date of birth
} else {
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//Test the legality of the date of birth
}
if((idcard)) return Errors[0];
alert(Errors[0]);
else return Errors[2];
alert(Errors[2]);
break;
case 18:
//18-digit identity number detection
//The legality check of the date of birth
//Leap year Month and Date: ((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
//Previous year, month and day: ((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
if ( parseInt((6,4)) % 4 == 0 || (parseInt((6,4)) % 100 == 0 && parseInt((6,4))%4 == 0 )){
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//Legality regular expression for dates of birth in leap years
} else {
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//The legality regular expression of the date of birth in the ordinary year is the regular expression of the date of birth.
}
if((idcard)){//Test the legality of the date of birth
// Calculate the check bit
S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
+ parseInt(idcard_array[7]) * 1
+ parseInt(idcard_array[8]) * 6
+ parseInt(idcard_array[9]) * 3 ;
Y = S % 11;
M = "F";
JYM = "10X98765432";
M = (Y,1);//Judge the check bit
if(M == idcard_array[17]) return Errors[0]; //Check bit of the detection ID
else return Errors[3];
alert(Errors[3]);
}
else return Errors[2];
alert(Errors[2]);
break;
default:
return Errors[1];
alert(Errors[1]);
break;
}
}