<scripttype="text/javascript">
alert(isIdCardNo("440781197007220512"));
//--身份证号码验证-支持新的带x身份证
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="输入身份证号码长度不对!";
//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="错误的身份证号码!.";
//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="身份证中日期信息不正确!.";
//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="身份证效验位错误!...正确为:"+intCheckDigit+".";
//alert(error);
returnfalse;
}
}
else{//lengthis15
//checkdate
vardate6=idNumber.substring(6,12);
if(checkDate(date6)==false){
//alert("身份证日期信息有误!.");
returnfalse;
}
}
//alert("Correct.");
returntrue;
}
functioncheckDate(date)
{
returntrue;
}
</script>