SoFunction
Updated on 2025-04-10

JS writes functions to implement verification function for the last digit of ID number

The second generation ID number is 18 digits, and the calculation method of the last digit (18th digit) is:

1. Multiply the 17-digit number of the previous ID number by different coefficients. The coefficients from the first to the seventeenth position are:

7-9-10-5-8-4-2-1-6-3-7-9-10-5-8-4-2

2. Add the result of multiplying these 17-digit numbers and coefficients

3. Use the addition and divide by 11 to see what the remainder is?

4. The remainder may only have 11 numbers: 0-1-2-3-4-5-6-7-8-9-10. The number of the last ID card corresponding to each number is: 1-0-X-9-8-7-6-5-4-3-2. That is, if the remainder is 2, the Ⅹ of the Roman numeral will appear on the 18th digit of the ID card. If the remainder is 10, the last number of the ID card is 2.

For example: The ID number of a man is 34052419800101001X. When verifying whether the last bit is correct, you first need to obtain the sum of the products of the first 17 bits is 189, and then divide 189 by 11 to get the result of 17+2/11, which means that the rest is 2. Finally, through the corresponding rules, you can know that the number corresponding to remainder 2 is x. Therefore, it can be determined that the last digit of this ID number is qualified.

The verification method is as follows:

//Verification methodfunction verifyCode(id){
 if( !=18 )
  return false;
 /*1. The coefficients from the first position to the seventeenth position are:
    7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2
    Add the result of multiplying these 17-digit numbers and coefficients.  */ 
 var arr = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
 var sum = 0;
 for(var i=0; i<; i++){
  sum += parseInt((i)) * arr[i];
 }
 //2. Use the addition and divide by 11 to see the remainder. var c = sum%11;
 //3. The number of the last ID card corresponding to each is: 1-0-X-9-8-7-6-5-4-3-2 var ch = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
 var code = ch[c];
 var last = (17);
 last = last=='x' ? 'X': last;
 return last == code;
 }

Test this method:

var id = "34052419800101001X";
 (verifyCode(id));

The above is the JS writing function introduced by the editor to implement the verification function of the last digit of the ID number. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!