Javascript ID card number verification function supports x

Source: Internet
Author: User

Function isidcardno (Num)
{
VaR factorarr = new array );
VaR error;
VaR vararray = new array ();
VaR intvalue;
VaR lngproduct = 0;
VaR intcheckdigit;
VaR intstrlen = num. length;
VaR idnumber = num;
// Initialize
If (intstrlen! = 15) & (intstrlen! = 18 )){
// Error = "the length of the ID card number entered is incorrect! ";
// Alert (error );
// Frmadduser.txt idcard. 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 = "Incorrect ID number !. ";
// Alert (error );
// Frmadduser.txt idcard. 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 = "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 % 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 = "Incorrect ID card verification space !... Correct: "+ intcheckdigit + ".";
// Alert (error );
Return false;
}
}
Else {// length is 15
// Check date
VaR date6 = idnumber. substring (6, 12 );
If (checkdate (date6) = false ){
// Alert ("the date of the ID card is incorrect !. ");
Return false;
}
}
// Alert ("Correct .");
Return true;
}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/21aspnet/archive/2007/03/23/1539273.aspx

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.