(1) Structure of 18 ID number
The citizen identity number is a characteristic combination code, consisting of a seventeen-digit body code and a one-digit check code.
The order from left to right is: six-digit address code, eight-digit date of birth code, three-digit sequence code and one-digit check code.
1. Address code
Indicates the administrative area division code of the county (city, banner, district) where the coding object's permanent residence is located, and shall be implemented in accordance with the provisions of GB/T2260.
2. Date of birth code
Indicates the year, month, and day of birth of the encoding object. It is implemented in accordance with the provisions of GB/T7408. There is no separator between the year, month, and day codes.
3. Sequence code
Indicates that within the area identified by the same address code, the sequence numbers are assigned to people born in the same year, month, and day. The odd numbers of the sequence codes are assigned to males, and the even numbers are assigned to females.
4. Check code calculation steps
(1) Weighted summation formula of seventeen-digit ontology code
S = Sum(Ai * Wi), i = 0, ... , 16, first sum the weights of the first 17 digits
Ai: represents the digital value of the ID number at the i-th position (0~9)
Wi:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 (indicates the weighting factor at the i-th position)
(2) Calculation model
Y = mod(S, 11)
(3) According to the module, find the corresponding check code
Y: 0 1 2 3 4 5 6 7 8 9 10
Check code: 1 0 X 9 8 7 6 5 4 3 2
(2) Program example for obtaining the last digit of the check code based on the 17-digit ontology code
Copy the code code as follows:
public class Id18 {
int[] weight={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; //Seventeen-digit ontology code weight
char[] validate={ '1','0','X','9','8','7','6','5','4','3','2'} ; //mod11, corresponding to the check code character value
public char getValidateCode(String id17){
int sum=0;
int mode=0;
for(int i=0;i<id17.length();i++){
sum=sum+Integer.parseInt(String.valueOf(id17.charAt(i)))*weight[i];
}
mode=sum%11;
return validate[mode];
}
public static void main(String[] args){
Id18 test=new Id18();
System.out.println("Verification code of this ID card:"+test.getValidateCode("14230219700101101")); //Verification code of this ID card: 3
}
}
(3) Explanation
1. The program can obtain the corresponding verification code based on the existing 17-digit ontology code.
2. This program can eliminate ID numbers with incorrect verification codes.
3. The birth year of the 15-digit ID card uses the last 2 digits of the year, without the last 1 digit of the check code.
4. A complete ID card has 18 digits, and the last check digit may be a non-digit. In one of our projects, the database saves the first 17 digits, which can speed up some SQL statements (such as inner join)! ! !