An 18-digit ID card verification calculation function

Source: Internet
Author: User

Because I needed to perform the escalation, verification, and query of the 15-digit old ID card number, and did not find any ready-made functions, I wrote a simple process and hoped to help my friends.
This function has a single function and can only verify whether the 18th-bit number is correct or obtain the 18th-bit number. Other functions can be expanded by yourself!

<%
'Version: 1.0.1
'Author: sfply (sfply@163.com)
'Last modified: 2004/7/17 12:03
'Src is the ID card number, which can be 15 or 18 digits. Only the verification code can be returned for 15 digits.
The value of the 'ichk parameter is true or false. It indicates whether the SRC 18-digit ID card is verified, and whether the 18th-digit number is correct to determine whether the ID card is valid. The return value is true or false.
'False' indicates that the correct verification code is returned. The returned value is (1 ~ X)
Dim myidentify
Myidentify = "36050219781218133? "

Response. Write chkidentiycard (myidentify, false)

Function chkidentiycard (SRC, ichk)
Dim mywi, myai, mysrc (17), I, mycount
Myai = "10x98765432"
Mywi = Split ",",")
If ichk then
If Len (SRC) = 18 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 11) + 1,1) = right (SRC, 1) then
Chkidentiycard = true'. True indicates the valid ID card verification code.
Else
Chkidentiycard = false'. False indicates that the ID card verification code is invalid.
End if
Else
Chkidentiycard = false' returns false because it is not an 18-digit ID card.
End if
Else
If Len (SRC) = 15 or Len (SRC) = 18 then
If Len (SRC) = 15 then src = mid (SRC,) & "19" & Mid (SRC)
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) +) 'returns the correct Verification Code
Else
Chkidentiycard = false' do not enter a 15-digit or 18-digit ID card number
End if
End if
End Function
%>

How to calculate ID card 18th is as follows:

According to the provisions on citizenship numbers in the National Standard of the People's Republic of China GB 11643-1999, a citizenship number is a feature combination code consisting of a 17-digit digital ontology code and a digital verification code. The six-digit address code, eight-digit birth date code, three-digit sequence code, and one-digit verification code are arranged from left to right.

The address code indicates the Administrative Code of the county (city, flag, district) where the resident account of the encoding object is located. The birthdate code indicates the year, month, and day of the encoding object. The year is represented by four digits, and there is no separator between the year, month, and day. The sequence number indicates the sequence number of persons born in the same year, month, or day within the region specified by the same address code. The odd number of the sequence code is assigned to men, and the even number is assigned to women. The verification code is calculated based on the first 17-digit code according to the ISO 7064: 1983.mod 11-2 verification code. The following is an example of this calculation method.

The 15-digit ID card code first expands the birth year to four digits. Simply, it adds 19 digits, but this is not used by people born in 1900 (there are not many such life stars)

The subject code of a male citizenship number is 34052419800101001. First, calculated according to formula (1:

SIGMA (AI x WI) (mod 11 ).......................................... (1)

Formula (1:
I ---- indicates 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;
Wi ---- indicates the weighting factor at position I. The value is calculated based on 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 1 A1

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

AI x wi 21 36 0 25 16 16 2 9 48 0 9 0 5 0 0 2 A1

Calculate according to formula (1:

SIGMA (AI x WI) = (21 + 36 + 0 + 25 + 16 + 16 + 2 + 9 + 48 + 0 + 0 + 9 + 0 + 5 + 0 + 0 + 2) = 189

189 usd11 = 17 + 2/11

SIGMA (AI x WI) (mod 11) = 2

Then, based on the calculation result, find the corresponding verification code from the following table, where X indicates that the calculation result is 10:

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
According to the preceding table, the verification code of the calculation result 2 is found to 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.