<script language= "Web Effects" >
<!--
function Isidcard (idcard) {
var area={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"}
var Idcard,y,jym;
var s,m;
var idcard_array = new Array ();
Idcard_array = Idcard.split ("");
Regional inspection
if (Area[parseint (Idcard.substr (0,2))]==null) return false;
Identification number and format test
Switch (idcard.length) {
Case 15:
if ((parseint (Idcard.substr (6,2)) +1900% 4 = 0 | | ((parseint (Idcard.substr (6,2)) +1900% = = 0 && (parseint (Idcard.substr (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 Birth date legality
} 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 date of birth legality
}
if (Ereg.test (Idcard)) return true;
else return false;
Break
Case 18:
18-digit identification number detection
Validity of Birth date check
Leap Month 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-2][0-9]))
Flat Month 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 (Idcard.substr (6,4))% 4 = 0 | | (parseint (Idcard.substr (6,4))% = = 0 && parseint (idcard.substr (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]$/;//validity of a leap year birth date regular expression
} 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]$/;//excepting the legality of the date of birth regular expression
}
if (Ereg.test (Idcard)) {//test date of birth legality
return true; Check digit of Detection ID
}else return false;
Break
Default
return false;
Break
}
}
function Iscard (value) {
if (Isidcard (value) ==false) {
Alert ("Not a valid ID number!") ")
}else{
Alert ("ID card number is correct!!") ");
}
}
-->
</script>
<body>
<input type= "text" name= "AAAA" onblur= "Iscard (this.value)" >
</body>
Method Two
JS ID number validation function supports the number with X
--Identification number verification-support for new X ID card
Functionisidcardno (num)
{
Varfactorarr=newarray (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);
Varerror;
Varvararray=newarray ();
Varintvalue;
varlngproduct=0;
Varintcheckdigit;
Varintstrlen=num.length;
Varidnumber=num;
Initialize
if ((intstrlen!=15) && (intstrlen!=18)) {
error= "Enter ID number length is not correct!" ";
alert (error);
Frmadduser.txtidcard.focus ();
Returnfalse;
}
Checkandsetvalue
for (i=0;i<intstrlen;i++) {
Vararray[i]=idnumber.charat (i);
if (vararray[i]< ' 0 ' | | | Vararray[i]> ' 9 ') && (i!=17)) {
Error= "wrong ID number!.";
alert (error);
Frmadduser.txtidcard.focus ();
Returnfalse;
}elseif (i<17) {
Vararray[i]=vararray[i]*factorarr[i];
}
}
if (intstrlen==18) {
Checkdate
Vardate8=idnumber.substring (6,14);
if (Checkdate (Date8) ==false) {
Error= "The date information in the ID card is incorrect!.";
alert (error);
Returnfalse;
}
Calculatethesumoftheproducts
for (i=0;i<17;i++) {
Lngproduct=lngproduct+vararray[i];
}
Calculatethecheckdigit
intcheckdigit=12-lngproduct%11;
Switch (intcheckdigit) {
Case10:
intcheckdigit= ' x ';
Break
CASE11:
intcheckdigit=0;
Break
Case12:
Intcheckdigit=1;
Break
}
Checklastdigit
if (Vararray[17].touppercase ()!=intcheckdigit) {
Error= "ID parity bit error!... Correct for: "+intcheckdigit+";
alert (error);
Returnfalse;
}
}
Else{//lengthis15
Checkdate
Vardate6=idnumber.substring (6,12);
if (Checkdate (DATE6) ==false) {
Alert ("ID date information is incorrect!.");
Returnfalse;
}
}
Alert ("correct.");
Returntrue;
}