ID card number verification-supports new x ID card

Source: Internet
Author: User
// -- ID card number verification-supports 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 ! =   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 ("Incorrect ID Card Date information !. ");
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.