A 18-digit ID card verification function

xiaoxiao2021-03-06  37

Due to the need to upgrade and check 15 old ID card numbers, query processing, and no ready-made functions, so I wrote a simple process, I hope to help friends needed. The function of this function is single. You can only check if the 18th digit is correct or get the 18th digit number, and the other features are left to everyone to expand!

<% 'Version: 1.0.1' Author: sfply (sfPly@163.com) 'Last Modified: 2004/7/17 12:03' src is the ID number, can be 15 bits or 18, 15 You can only return the verification code to use the 'Ichk parameter to take the value of the value, the true representative checks if the SRC is 18-digit ID, and checks if the 18th bit is correct, determine if a valid ID card is valid, return only value true or false. 'Fake representative returns the correct check code, the return value is (1 ~ x) DIM myidentitymyidentify = "36050219781218133?"

Response.write chkidentiycard (MyIdentify, false)

Function Chkidentiycard (SRC, ICHK) DIM MYWI, MyAi, MySRC (17), 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 IX (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) Ten chkidentiycard = true 'Returns, true is a legal ID card Verification code else chkidentiycard = false 'Return results, false is an illegal ID card verification code end if else chkidentiycard = false' Because not 18 identity card, return false end if else if len (src) = 15 or Len (src) = 18 THEN IF LEN (SRC) = 15 THEN SRC = MID (SRC, 1, 6) & "19" & 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 (mycount mod 11) 1,1) 'Returns the correct verification code else chkidentiycard = false' input is not 15 or 18 ID number End if end if End function%> About the identity card, how to calculate, the principle is as follows

According to the provisions of the citizen identity number in the National Standard GB 11643-1999 in the People's Republic of China, the citizen identity number is the characteristic group code, consists of the seventeenth digital body code and a digital check code. Arrange the order from left to right as: six digit address code, eight digit born date code, three digital sequence code and one digital check code. The address code represents the administrative region of the county (city, flag, district) in the county (city, flag, district) of the coding object. The birthday period indicates the year, month, day of the birthday, month, and the year, the year, the year, month, and day without separator. The sequence code indicates the sequence number of the person born in the same year, month, and day. The odd number of sequence codes is given to men, even giving women. The check code is based on the seventeenth digit of the previous seventeen digits, calculated by the ISO 7064: 1983.MOD 11-2 check code. The calculation method will be described below.

15 identity card coding first expanded the birth year to 4 digits, simple is to increase a 19, but this is not used for people born in 1900 (such birthday is not much)

A male citizenship number is 34052419800101001, first, according to formula (1):

Σ (AI × Wi) (MOD 11) ........................................ (1)

Equation (1): i ---- Indicates the number character from the zip number, including the calibration code; AI ---- represents the number character value at the first position; Wi ---- show The weighting factor at the i position 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 0 1 A1

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

Ai × Wi 21 36 0 25 16 16 2 9 48 0 0 9 0 5 0 0 2 A1

Calculated according to equation (1):

Σ (AI × Wi) = (21 36 0 25 16 16 2 9 48 5 0 0 2) = 189

189 ÷ 11 = 17 2/11

Σ (AI × Wi) (MOD 11) = 2

The corresponding check code is then isolated from the following table according to the calculated result, where x represents the calculation result 10:

Σ (AI × Wi) (MOD 11) 0 1 2 3 4 5 6 7 8 9 10 Check code character value AI 1 0 x 9 8 7 6 5 4 3 2 According to the top table, the calculation result is 2 schools The code for 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

转载请注明原文地址:https://www.9cbs.com/read-59753.html

New Post(0)