ID number verification-support for new X ID

Source: Internet
Author: User
Tags date array return
--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!= 18)) {
Error = "Input 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 ((Vararray[i] < ' 0 ' | | | vararray[i] > ' 9 ') && (i!= 17)) {
Error = "Wrong ID number!.";
alert (error);
FrmAddUser.txtIDCard.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 = "The date information in the ID card is incorrect!.";
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 = "id parity bit wrong!... 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 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.