JavaScript ID card number verification-supports new x ID card

Source: Internet
Author: User
1 // -- ID card number verification-new x ID card supported
2 function isIdCardNo (num)
3 {
4 var factorArr = new Array );
5 var error;
6 var varArray = new Array ();
7 var intValue;
8 var lngProduct = 0;
9 var intCheckDigit;
10 var intStrLen = num. length;
11 var idNumber = num;
12 // initialize
13 if (intStrLen! = 15) & (intStrLen! = 18 )){
14 // error = "the length of the ID card number entered is incorrect! ";
15 // alert (error );
16 // frmAddUser.txt IDCard. focus ();
17 return false;
18}
19 // check and set value
20 for (I = 0; I <intStrLen; I ++ ){
21 varArray [I] = idNumber. charAt (I );
22 if (varArray [I] <'0' | varArray [I]> '9') & (I! = 17 )){
23 // error = "Incorrect ID number !. ";
24 // alert (error );
25 // frmAddUser.txt IDCard. focus ();
26 return false;
27} else if (I <17 ){
28 varArray [I] = varArray [I] * factorArr [I];
29}
30}
31 if (intStrLen = 18 ){
32 // check date
33 var date8 = idNumber. substring (6, 14 );
34 if (checkDate (date8) = false ){
35 // error = "incorrect date information in ID card !. ";
36 // alert (error );
37 return false;
38}
39 // calculate the sum of the products
40 for (I = 0; I <17; I ++ ){
41 lngProduct = lngProduct + varArray [I];
42}
43 // calculate the check digit
44 intCheckDigit = 12-lngProduct % 11;
45 switch (intCheckDigit ){
46 case 10:
47 intCheckDigit = 'X ';
48 break;
49 case 11:
50 intCheckDigit = 0;
51 break;
52 case 12:
53 intCheckDigit = 1;
54 break;
55}
56 // check last digit
57 if (varArray [17]. toUpperCase ()! = IntCheckDigit ){
58 // error = "Incorrect ID card verification space! Correct: "+ intCheckDigit + ".";
59 // alert (error );
60 return false;
61}
62}
63 else {// length is 15
64 // check date
65 var date6 = idNumber. substring (6, 12 );
66 if (checkDate (date6) = false ){
67 // alert ("Incorrect ID Card Date !. ");
68 return false;
69}
70}
71 // alert ("Correct .");
72 return true;
73}

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.