网(LieHuo.Net)教程 请看实例代码:
以下为引用的内容: <script language="javascript"> function isChinaIDCard(){ StrNo = document.getElementById("<%=txtCarID.ClientID%>").value; if(StrNo.length == 15){ if(!isValidDate("19"+StrNo.substr(6,2),StrNo.substr(8,2),StrNo.substr(10,2))){return false;} }else if(StrNo.length == 18){ if (!isValidDate(StrNo.substr(6,4),StrNo.substr(10,2),StrNo.substr(12,2))){return false;} }else{ showLayer('popupBox',"输入的身份证号码必须为15位或者18位!"); return false; } if (StrNo.length==18) { var a,b,c if (!isNumber(StrNo.substr(0,17))){showLayer('popupBox',"身份证号码错误,前17位不能含有英文字母!");return false;} a=parseInt(StrNo.substr(0,1))*7+parseInt(StrNo.substr(1,1))*9+parseInt(StrNo.substr(2,1))*10; a=a+parseInt(StrNo.substr(3,1))*5+parseInt(StrNo.substr(4,1))*8+parseInt(StrNo.substr(5,1))*4; a=a+parseInt(StrNo.substr(6,1))*2+parseInt(StrNo.substr(7,1))*1+parseInt(StrNo.substr(8,1))*6; a=a+parseInt(StrNo.substr(9,1))*3+parseInt(StrNo.substr(10,1))*7+parseInt(StrNo.substr(11,1))*9; a=a+parseInt(StrNo.substr(12,1))*10+parseInt(StrNo.substr(13,1))*5+parseInt(StrNo.substr(14,1))*8; a=a+parseInt(StrNo.substr(15,1))*4+parseInt(StrNo.substr(16,1))*2; b=a%11; if (b==2) //最后一位为校验位 { c=StrNo.substr(17,1).toUpperCase(); //转为大写X } else { c=parseInt(StrNo.substr(17,1)); } switch(b) { case 0: if ( c!=1 ) {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:1");return false;}break; case 1: if ( c!=0 ) {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:0");return false;}break; case 2: if ( c!="X") {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:X");return false;}break; case 3: if ( c!=9 ) {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:9");return false;}break; case 4: if ( c!=8 ) {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:8");return false;}break; case 5: if ( c!=7 ) {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:7");return false;}break; case 6: if ( c!=6 ) {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:6");return false;}break; case 7: if ( c!=5 ) {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:5");return false;}break; case 8: if ( c!=4 ) {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:4");return false;}break; case 9: if ( c!=3 ) {showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:3");return false;}break; case 10: if ( c!=2 ){showLayer('popupBox',"身份证好号码校验位错:最后一位应该为:2");return false;} } } else {//15位身份证号 if (!isNumber(StrNo)) {showLayer('popupBox',"身份证号码错误,前15位不能含有英文字母!");return false;} } return true; } function hideLayer(id) { </script> |
下一篇 ACCESS集锦