JavaScript ID number validation function support with X

Source: Internet
Author: User

 

//--identification 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!=)) {
//error = "Enter the 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 (Vararr Ay[i] < ' 0 ' | | Vararray[i] > ' 9 ') && (i!=) {
//error = "Wrong ID number!.";
//alert (Error);
//frmadduser.txtidcard.focus ();
return false;
} else if (I <) {
Vararray[i] = Vararray[i]*factorarr[i];
}
}
if (Intstrlen = =) {
//check date
var date8 = idnumber.substring (6,14);
if (checkdate (Date8) = False) {
//error = "Incorrect date information in ID card!.";
//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%
Switch (intcheckdigit) {
Case 10: intcheckdigit = ' X ';
break;
Case One:
intcheckdigit = 0;
break;
Case:
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
//check date
var date6 = idnumber.substring (6,12);
if (checkdate) = = False) {
//alert ("ID date information is incorrect!.");
return false;
}

//alert ("correct.");
return true;
}

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.