JS to achieve ID number 15-bit to 18-bit when the last algorithm

Source: Internet
Author: User
js| algorithm <script language= "JavaScript" >
<!--
var Lastnumber;
var id = "15-bit ID number"//15-digit ID number
var getnum=eval (Id.charat (0) *7+id.charat (1) *9+id.charat (2) *10+id.charat (3) *5+id.charat (4) *8+id.charat (5) *4+ Id.charat (6) *2+id.charat (7) *1+id.charat (8) *6+id.charat (9) *3+id.charat (a) *7+id.charat (one) *9+id.charat (12) *10+ Id.charat (*5+id.charat) *8+id.charat *4+id.charat (16) *2);
getnum=getnum%11;
Switch (getnum) {
Case 0:
lastnumber= "1";
Break
Case 1:
lastnumber= "0";
Break
Case 2:
Lastnumber= "X";
Break
Case 3:
Lastnumber= "9";
Break
Case 4:
Lastnumber= "8";
Break
Case 5:
Lastnumber= "7";
Break
Case 6:
Lastnumber= "6";
Break
Case 7:
Lastnumber= "5";
Break
Case 8:
Lastnumber= "4";
Break
Case 9:
Lastnumber= "3";
Break
Case 10:
Lastnumber= "2";
Break
}
document.write (Lastnumber);
return lastnumber;

-->
</SCRIPT>

Reference content:

According to the standard GB 11643-1999〗 of the People's Republic of China, the citizen identification number is a characteristic combination code, which consists of 17 digit ontology code and a digital check code. The order is from left to right: six digit address code, eight digit birth date code, three digit sequential code and one digit parity code.

The address code represents the administrative division code of the county (city, Flag, district) of the resident residence of the encoding object. The date code represents the year, month, and day of the encoding object's birth, where the year is represented by a four-digit number, and the year, month, and day are not separated. The sequential code represents the sequence number of persons born in the same same address code, in the range of the area identified by the same one. The odd number of sequential codes is given to men, even to females. The check code is based on the front 17 digit code, according to the ISO 7064:1983.mod 11-2 check code to calculate the inspection code. The following example illustrates the calculation method.

The 15-digit ID Code First expands the year of birth to 4 digits, simply by adding a 19, but this is not used for people born in 1900 (the birthday is not much)

A male citizen ID number is 34052419800101001, first calculated according to the formula ⑴:

∑ (AIXWI) (mod 11) ..... ...... ...... ...... ...... ...... ...... (1)
Formula (1):
I----the number of digits from the to left including the check code;
AI----represents the number character value on position I;
The Wi----shows the weighting factor in position I, whose numerical value is calculated according to the formula wi=2 (n-1) (mod 11).
I 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

Ai 3 4 0 5 2 4 1 9 8 0 0 1 0 1 0 0 1 A1

Wi. 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1

AIXWI 0 2 9/0 0 9 0 5 0 0 2 A1

Calculated according to the formula (1):
∑ (AIXWI) = (21+36+0+25+16+16+2+9+48++0+0+9+0+5+0+0+2) = 189

189÷11 = 17 + 2/11

∑ (AIXWI) (mod 11) = 2

Then, based on the results of the calculation, the corresponding checksum code is detected from the table below, where x indicates that the result is 10:

∑ (AIXWI) (mod 11) 0 1 2 3 4 5 6 7 8 9 10
Parity code character value AI 1 0 X 9 8 7 6 5 4 3 2
According to the table above, the verification code with the result of 2 is found to be that the citizenship number of the person should be 34052419800101001X.

A[0]*7+a[1]*9+a[2]*10+a[3]*5+a[4]*8+a[5]*4+a[6]*2+a[7]*1+a[8]*6+a[9]*3
+a[10]*7+a[11]*9+a[12]*10+a[13]*5+a[14]*8+a[15]*4+a[16]*2

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.