Formula for Calculating the last verification code of the ID card number
Source: Internet
Author: User
China's current use of citizen ID card numbers are subject to two national standards: [GB 11643-1989] and [GB 11643-1999 〗. [GB 11643-1989] indicates a 15-digit ID card number. The numbers are arranged from left to right in the order of six-digit address codes, six-digit birth date codes, and three-digit sequential codes, the birthdate Code does not contain the number of centuries. [GB 11643-1999] specifies the 18-digit ID card number. A citizenship number is a combination of features and consists of a 17-digit 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 area of the county (city, flag, district) where the resident account of the encoding object is located. Code . 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 reason for Division 11 is the function used to calculate the verification code. See the following function: formula: Σ (A [I] * W [I]) mod 11 (I = 2, 3 ,..., 18) (1) "*" indicates the serial number of each digit of the ID card number, ranging from right to left, 18 to 1. A [I] ----- indicates the ID card number on the I-digit number W [I] ----- indicates the weight on the I-digit W [I] = 2 ^ (I-1) moD 11 calculation formula (1). The result is R. Find the verification code corresponding to r according to the following table, that is, the verification code C for the ID card number. R 0 1 2 3 4 5 6 7 8 9 10 C 1 0x9 8 7 6 5 4 3 2 from this we can see that X is 10, and 10 in the Roman numerals is X, therefore, the new standard ID card number may contain non-digit letters X. ~ (Important )~ This function is expanded to a [1] * W [1] + A [2] * W [2] + ...... + A [18] * W [18] =?? Mod11 = "? For example: 22mod11 = 2 23mod22 is also 2 33mod11 = 3 is out of the following number, only the operator does not take the remainder, so from the function and its expansion, we need to evaluate the model for 11, all except 11 and below are columns: * this function is used to enter a 15-digit, 17-digit, or 18-digit ID card number, returns the last digit ** --------------------------------- function sfzjyparameters ciddo casecase Len (alltrim (CID) = 15cid = stuff (alltrim (CID), 7,0, "19") after verification ") case Len (alltrim (CID) = 18 or Len (alltrim (CID) = 17cid = left (alltrim (CID), 17) otherwisereturn. f. endcaseif Len (alltrim (CID) #17 return. f. endifnsum = V Al (substr (CID,) * 7; + val (substr (CID,) * 9; + val (substr (CID,) * 10; + val (substr (CID,) * 5; + val (substr (CID,) * 8; + val (substr (CID, 6, 1) * 4; + val (substr (CID,) * 2; + val (substr (CID,) * 1; + val (substr (CID, 9, 1) * 6; + val (substr (CID, 10, 1) * 3; + val (substr (CID, 11, 1) * 7; + val (substr (CID, 12, 1) * 9; + val (substr (CID,) * 10; + val (substr (CID,) * 5; + va L (substr (CID, 15,1) * 8; + val (substr (CID, 16,1) * 4; + val (substr (CID, 17,1 )) * 2 * calculate the check_number = int (12-nsum % 11) % 11) If check_number = 10check_number = 'X' endifreturn check_numberendfunc * ------------------------- ** function: if you enter a 15-or 18-digit ID card number, the correct 18-digit ID card number is returned. ** --------------------------- Function idcardtfparameters cnumber # define invalidsize "Incorrect ID number length! "# Define invalidchar" the ID card number contains invalid characters! "# Define invaliddate" invalid Date of birth! "# Define invalidreturnvalue ". f. "Private cstringdo casecase Len (cnumber) = 15 cstring = stuff (cnumber, 7,0," 19 ") Case Len (cnumber) = 18 cstring = left (alltrim (cnumber), 17) otherwisemessagebox (invalidsize, 48, "") return invalidreturnvalueendcaseprivate I, n, iretstore 0 to iretfor I = 1 to 17n = substr (cstring, I, 1) if not isdigit (n) MessageBox (invalidchar, 48, "") return invalidreturnvalueendifn = 2 ^ (18 -I) % 11 * val (n) iret = iret + nendforiret = iret % 11 + 1 private olddateset, oldcenturyprivate oldstrictdate, birthdayolddateset = set ("date ") oldcentury = set ("century") oldstrictdate = set ("strictdate") set date ansiset century onset strictdate to 0 Birthday = ctodd (substr (cstring, 7,4) + "-" + substr (cstring, 11, 2) + "-" + substr (cstring, 13, 2) set strictdate to & oldstrictdateset century & oldcenturyset date & Olddatesetif empty (birthday) MessageBox (invaliddate, 48, "message prompt") return invalidreturnvalueendifreturn cstring + substr ("10x98765432", iret, 1) endfunc * signature **: This function checks whether the 15-or 18-digit ID card number is valid. ** ----------------------------- function sfzynlparameters lstr & parameter: The number entered by lstr is local lstr, relyn, tsfzlocal M1, M2, M3, M4, M, I, R, C, AI, wiset talk offset date to ansiset cent onrelyn =. f. & Return Value tsfz = allt (lstr) * M1, M2, M3, and M4 are used to indicate whether the four conditions are true or not. t. to M1, M2, M3, M4 * condition 1: only 15 or 18-bit M1 = IIF (LEN (tsfz) = 15 or Len (tsfz) = 18 ,. T .,. f .) if Len (tsfz) = 15 & 15 digits for I = 1 to 15 & check if each digit is a number M = ASC (subs (tsfz, I, 1) if m <48 or M> 57 & amp; M2 =. f. & if one of them is not, do not query exitendifendform = "19" + subs (tsfz,) & the early dates were the M = m + of the last century ". "+ subs (tsfz, 9, 2) M = m + ". "+ subs (tsfz, 11,2) M = ctodd (m) if isnull (M) or isblank (m) m3 =. f. & incorrect birthday endifendifif Len (tsfz) = 18 & 18 bits F Or I = 1 to 17 m = ASC (subs (tsfz, I, 1) If M <48 or M> 57m2 =. f. exitendifendform = Subs (tsfz, 7,4) M = m + ". "+ subs (tsfz, 11,2) M = m + ". "+ subs (tsfz, 13, 2) M = ctodd (m) if isnull (M) or isblank (m) m3 =. f. endifr = 0 & calculate check bit for I = 18 to 2 step-1ai = Val (subs (tsfz, 19-i, 1) Wi = Mod (2 ^ (I-1), 11) R = R + AI * winextr = Mod (R, 11) do casecase r = 0C = "1" case R = 1C = "0" case R = 2C = "X" otherc = alltrim (STR (12-r )) endcaseif uppe (subs (tsfz, 18, 1) <> cm4 =. f. & check bit and the last digit of the original code are not If all four conditions of endifendif * are true, return. t. relyn = IIF (M1 and M2 and M3 and M4 ,. T .,. f .) retu relynendfun ** --------------------------- ** function: enter a 15-or 18-digit ID card number, and return the 18-digit ID card number after verification. If the ID card number is invalid, then, the system returns a blank ** response func sfjypara msfzon erro retu'' dime T (17) priv msfz, T, Sn, imsfz = allt (msfz) Do casecase Len (msfz) = 15 msfz = left (msfz, 6) + '19' + subs (msfz, 7) Case Len (msfz) = 18 msfz = left (msfz, 17) otheretu ''endcfor I = 1 to 17if! Isdi (subs (msfz, I, 1) retu''' endiendfif! Left (values, 2) $'11,, 81, 82 'retu'' endiif empt (date (Val (subs (msfz,), Val (subs (msfz,), Val (subs (msfz, 13, 2) retu''' endisn = 0 T (1) = 7 T (2) = 9 T (3) = 10 t (4) = 5 T (5) = 8 T (6) = 4 T (7) = 2 t (8) = 1 T (9) = 6 T (10) = 3 T (11) = 7 T (12) = 9 T (13) = 10 t (14) = 5 T (15) = 8 T (16) = 4 T (17) = 2For I = 1 to 17sn = Sn + val (subs (msfz, I, 1) * t (I) endfsn = Mod (Sn, 11) on erroretu msfz + subs ('10x98765432', Sn + 1, 1)
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.