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