18-digit ID card Verification Algorithm
ID card verification code algorithm
ID card verification code generation method:
SIGMA (ai x Wi) (mod 11)
I: the serial number of the character from the start to the left, including the verification code;
Ai indicates the number character value at position I;
The weighted factor at the I position of Wi. Its value is Wi = mod (power (2, (n-1), 11)
I 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Wi 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1
Check Code:
SIGMA (ai x WI) (mod 11) 0 1 2 3 4 5 6 7 8 9 10
Verification Code character value: ai 1 0X9 8 7 6 5 4 3 2
The following are the verification functions:
FUNCTION sfzjy (num)
If len (num) = 15 then
CID = left (num, 6) & "19" & right (num, 9)
Elseif len (num) = 17 or len (num) = 18 then
CID = left (num, 17)
End if
NSum = mid (cID, 1, 1) * 7
NSum = nsum + mid (cID, 2, 1) * 9
NSum = nsum + mid (cID, 3, 1) * 10
NSum = nsum + mid (cID, 4,1) * 5
NSum = nsum + mid (cID, 5, 1) * 8
NSum = nsum + mid (cID, 6, 1) * 4
NSum = nsum + mid (cID, 7,1) * 2
NSum = nsum + mid (cID, 8, 1) * 1
NSum = nsum + mid (cID, 9, 1) * 6
NSum = nsum + mid (cID, 10, 1) * 3
NSum = nsum + mid (cID, 11,1) * 7
NSum = nsum + mid (cID, 12, 1) * 9
NSum = nsum + mid (cID, 13, 1) * 10
NSum = nsum + mid (cID, 14,1) * 5
NSum = nsum + mid (cID, 15, 1) * 8
NSum = nsum + mid (cID, 16,1) * 4
NSum = nsum + mid (cID, 17,1) * 2
'* Calculate the check bit
Check_number = 12-nsum mod 11
If check_number = 10 then check_number = "X" elseIf check_number = 12 then check_number = "1" elseif check_number = 11 then check_number = "0" End if sfzjy = check_number
End function
Other verification:
Gender and date of birth:
Sfznum = ID card number
Lenx = len (sfznum)
If lenx = 15 then
Yy = "19" & mid (xian, 7,2)
Mm = mid (xian, 9, 2)
Dd = mid (xian, 11,2)
Aa = mid (xian, 15th) '15-digit identity card, which can be divided into two women
End if
If lenx = 18 then
Yy = mid (xian, 7,4)
Mm = mid (xian, 11,2)
Dd = mid (xian, 13, 2)
Aa = mid (xian, 17,1) '18-digit identity card with 17th digits, can be divided into two women
End if
If aa mod 2 = 0 then
Xb = "female"
Else
Xb = "male"
End if
If lenx = 18 then
If mid (xian, 18th) <> cstr (sfzjy (xian) then' if the-bit verification code is not equal to the calculated verification code, the ID card number is incorrect.
Response. write "prompt: Incorrect ID card checkpoint! "
Else
Response. write "result: the ID card number is verified as a valid number! "
End if
Else' if the input is a 15-digit number, the new 18-digit number is calculated.
Response. write "new ID:" & left (xian, 6) & "19" & right (xian, 9) & cstr (sfzjy (xian ))
End if
For household registration judgment, the database is required. It is not provided here.