A 18-bit ID check calculation function

Source: Internet
Author: User
Tags date
function | Because of the need for 15 old ID number to be up and check, query processing, and did not search the ready-made function, so I wrote a simple process, I hope to be able to help the needs of friends.
This function is single, only to verify that the 18th digit is correct or get the 18th digit number, other functions for everyone to expand it!

<%
' version:1.0.1
' Author:sfply (sfply@163.com)
' Last Modified:2004/7/17 12:03
' SRC is the ID card number, can be 15-bit or 18-bit, 15-bit can only return the verification code way to use
' Ichk parameter value TRUE or FALSE, true to verify SRC is 18-bit ID card, and verify that the 18th digit is correct number and determine whether a valid ID, return only a value of true or False
' False rep returns the correct checksum code, the return value is (1~x)
Dim myidentify
Myidentify = "36050219781218133?"

Response.Write Chkidentiycard (Myidentify,false)

Function Chkidentiycard (SRC,ICHK)
Dim mywi,myai,mysrc (I,mycount)
Myai = "10x98765432"
MyWi = Split ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2", ",")
If Ichk Then
If Len (SRC) = Then
For i = 0 to 16
MYSRC (i) = Mid (src,i+1,1)
Mycount = Mycount + MYSRC (i) * MYWI (i)
Next
If mid (Myai, mycount mod) +1,1 = right (src,1) then
Chkidentiycard = True ' Returns the result, true to legal ID authentication code
Else
Chkidentiycard = False ' Returns the result, false to illegal ID verification code
End If
Else
Chkidentiycard = False ' returns false because it is not a 18-bit ID
End If
Else
If Len (src) = or len (src) = Then
If Len (src) = then Src = Mid (src,1,6) & "M" & Mid (src,7,9)
For i = 0 to 16
MYSRC (i) = Mid (src,i+1,1)
Mycount = Mycount + MYSRC (i) * MYWI (i)
Next
Chkidentiycard = Mid (Myai, (mycount mod 11) +1,1) ' Returns the correct authentication code
Else
Chkidentiycard = False ' input No 15-bit or 18-digit ID number
End If
End If
End Function
%>

About the identity card 18th is how to calculate, the principle is as follows

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
%11





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.