JS ID Number _ ID number JS Verification

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax check checkdate date error html http 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>

&lt;script type= "text/web Effects" &gt;


//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!= &amp;&amp; (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&lt;intstrlen;i++) {


Vararray[i] = Idnumber.charat (i);


if ((Vararray[i] &lt; ' 0 ' | | | vararray[i] &gt; ' 9 ') &amp;&amp; (i!= 17)) {


error = "Wrong ID number!";


alert (Error);


//frmadduser.txtidcard.focus ();


return false;


} else if (I &lt; 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&lt;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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.