From October 1, 1999, the PRC State Council approved the establishment of a
citizen identification number system, and currently consists of an 18-digit code. This number has a function similar to that of the
social security number in the United States. Each citizen has a unique number that remains unchanged for their entire lifetime. •
Address code refers to the resident's location, where
administrative divisions (including
cities,
banners, and
districts) have their own specific codes. (For example, the code for
Xicheng District in
Beijing is 110102.) Change of address does not modify this code, however, which means that the code therefore reflects one's birthplace or the location of one's first-time card issuance (in the case where people are born before the resident identity card system was introduced). •
Date of Birth in the form YYYY-MM-DD. •
Order code is the code used to disambiguate people with the same date of birth and address code. Men are assigned to odd numbers, women assigned to even numbers. • The
Checksum is the final digit, which
confirms the validity of the ID number from the first 17 digits, utilizing
ISO 7064:1983, MOD 11-2. The checksum is obtained by: • Marking the Identity card number right-to-left a_1 , a_2 , \cdots , a_{18},a_1 for the parity-check codes; • Weight coefficient calculation W_i=2^{i-1}\ \bmod \ {11}; • : : • Calculation of S = \sum_{i=2}^{18} a_i \cdot W_i • a_1=(12-( S \ \bmod 11)) \bmod 11 ;Checksum derivation process in
Visual Basic Dim a, w, s ,id msgbox "This procedure for checking the identity card number and or-bit",vbokonly+vbinformation,"identity check procedures" id=inputbox("Enter the ID number 15 or 18 before the identity card numbers of 17 or","ID","11010519491231002") if vartype(id) <> 0 then 'Test the legality of the importation of numbers l = 0 do until l = 1 l = 1 p = "" if len(id) <> 17 then if len(id) <> 15 then l = 0 p = "enter the median is not correct, please enter 15 or 17-digit." end if end if for i = 1 to len(id) a = mid(id, i, 1) if asc(a) asc("9") then l = 0 p = p & vbCrLf & vbCrLf & "Please enter the number, do not include the characters“" & a & "”。" exit for end if next if l = 0 then id = inputbox("illegal input" & vbCrLf & vbCrLf & p, "input error", id) end if loop 'Will be number 15 or 17 places to number if len(id) = 15 then id = left(id, 6) & "19" & right(id, 9) end if 'Number 17 for the calculation of parity-check codes for i = 2 to 18 a = mid(id, 19-i, 1) w = 2^(i-1) mod 11 s = a * w + s next s = (12 - (s mod 11)) mod 11 if s = 10 then s = "X" 'After checking the number of output inputbox "the identity card number of the parity-check codes for the“" & s & "”" & vbcrlf & vbcrlf & "by checking the ID card numbers are as follows:", "Check completed", id & s end if ;Checksum derivation process in
TypeScript // Must input 17 bit string of RID from left to right function calcChecksum(rid: string) { const workArr = rid.split('').reverse(); let sum = 0; for (let j = 0; j ;Checksum derivation process in
Ruby • accepts first 17 digits of the card number and calculates checksum def calculate_checksum(card_id) sum = 0 card_id.reverse.each_char.with_index do |ch, idx| w = (2**(idx + 1)) % 11 sum += ch.to_i * w end (12 - sum % 11) % 11 end puts checksum('34262219840209049') # first 17 digits • => 10 puts checksum('63280119790817003') • => 6 ;Checksum derivation process in
Python >>> id_checksum = lambda s:(1 - 2 * int(s, 13)) % 11 >>> id_checksum('63280119790817003') 6L >>> id_checksum('34052419800101001') 10L # according to the standard, this means 'X' ;Checksum derivation process in
PHP /** *身份证验证,传入身份证,返回true即为正确。 ID number validation, pass in ID number, return true if success. *只能传入字符串,传入参数必须加引号。 can only pass in strings, parameter should be surrounded by quote marks. **/ function check_id_number($id) { if (strlen($id) != 18) { return false; } $temp = (str_split($id)); $temp[17] == 'x'|| $temp[17] == 'X' ? $check = 10 : $check = $temp[17]; array_pop($temp); $temp = array_reverse($temp); $sum = 0; foreach ($temp as $key => $value) { $w = pow(2, $key+1) % 11; $sum += $value * $w; } if ((12 - $sum % 11) % 11 != $check) { return false; } return true; } ;Checksum derivation process in
R > checkCode function(ID) { stopifnot(length(grep('^[0-9]{17}$', ID)) != 0) code print(checkCode('34262219840209049')) [1] 10 ==Usage of identification==