Last Update:2017-08-24
Source: Internet
Author: User
Keywords
Web page production
Ajax
javascript
Web Effects ID Number _ ID card number JS verification
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" > <head> <meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/> <TITLE>JS ID Card number JS verification </title>
<script type= "text/web Effects" > //alert (Isidcardno ("440781197007220512")); if (Isidcardno ("440781197007220512")) { alert ("Wrong ID number!") "); } //--ID Number verification-support for new X ID card function Isidcardno (num) { var Factorarr = new Array (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1); var error; var vararray = new Array (); var intvalue; var lngproduct = 0; var intcheckdigit; var intstrlen = num.length; var idnumber = num; //Initialize if (Intstrlen!= && (Intstrlen!= 18)) { error = "Input ID number length is not correct!" "; alert (Error); //frmadduser.txtidcard.focus (); return false; } //check and set value 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 (); return false; } else if (I < 17) { Vararray[i] = vararray[i]*factorarr[i]; } } if (Intstrlen = = 18) { //check Date var Date8 = idnumber.substring (6,14); if (checkdate (date8) = = False) { //error = "The date information in the ID card is incorrect!."; //alert (Error); return false; } //Calculate the sum of the products for (i=0;i<17;i++) { lngproduct = lngproduct + vararray[i]; } Calculate the check digit intcheckdigit = 12-lngproduct% 11; switch (intcheckdigit) { Case 10: intcheckdigit = ' x '; break; Case 11: intcheckdigit = 0; break; Case 12: intcheckdigit = 1; break; } //Check last digit if (vararray[17].touppercase ()!= intcheckdigit) { //error = "id parity bit error!... Correct for: "+ Intcheckdigit +". //alert (Error); return false; } } else{//length is 15 //check Date var date6 = idnumber.substring (6,12); if (checkdate (date6) = = False) { //alert ("ID date information is wrong!."); return false; } } //alert ("correct."); return true; }
function Checkdate (date) { return true; } </script>
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
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 </head>
<body> </body> </html>