Function checkidcard (strnumber)
The 'identification Card Number Format function' is a feature combination code,
'Consists of a 17-digit ontology code and a digital verification code.
The sorting order is from left to right: six-digit address code, eight-digit birth date code, three-digit sequence code, and one-digit verification code.
'Id card number length Determination
If Len (strnumber) <15 or Len (strnumber) = 16 or Len (strnumber) = 17 or Len (strnumber)> 18 then
Checkidcard = "ID card number has 15 or 18 digits"
Checkidcard = false
Exit Function
End if
'The last digit of the ID number may be X of an elderly person over 100 years old.
'So the last digit is excluded for digit format testing.
'Convert all to 17-digit format
Dim AI
If Len (strnumber) = 18 then
Ai = mid (strnumber, 1, 17)
Elseif Len (strnumber) = 15 then
Ai = strnumber
Ai = left (strnumber, 6) & "19" & Mid (strnumber, 7, 9)
End if
If not isnumeric (AI) then
Checkidcard = "in addition to the last digit, the ID card must be in numeric format! "
Exit Function
End if
'Mid function: the number of digits after which the start value is 1.
Dim stryear, strmonth, strday
Stryear = CINT (mid (AI, 7, 4 ))
Strmonth = CINT (mid (AI, 11, 2 ))
Strday = CINT (mid (AI, 13, 2 ))
Birthday = trim (stryear) + "-" + trim (strmonth) + "-" + trim (strday)
If isdate (birthday) then
If datediff ("YYYY", now, birthday) <-140 or cdate (birthday)> date () then
Checkidcard = "Incorrect ID card number! "
Exit Function
End if
If strmonth> 12 or strday> 31 then
Checkidcard = "Incorrect ID card number! "
Exit Function
End if
Else
Checkidcard = "Incorrect ID card number! "
Exit Function
End if
'Sequence code
'Indicates the sequence number of the person born on the same year, the same month, and the same day within the region specified by the same address code. The odd number of the sequence code is allocated to men, and the even number is allocated to women.
'Verification code
'17-digit ontology weighted sum formula
'S = sum (ai * WI), I = 0,..., 16, first sum the right of the first 17 digits
'Ai: indicates the ID card number at position I.
'Wi: indicates the weighting factor at position I.
'Wi: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
Arrverifycode = Split (", 0, x, 9, 8 ",",")
Wi = Split ",",")
Dim I, totalmulaiwi
For I = 0 to 16
Totalmulaiwi = totalmulaiwi + CINT (mid (AI, I + 1, 1) * WI (I)
Next
'Computing Model
'Y = Mod (S, 11)
'Get the corresponding verification code through the modulo
'Y: 0 1 2 3 4 5 6 7 8 9 10
'Verification code: 1 0x9 8 7 6 5 4 3 2
Dim modvalue
Modvalue = totalmulaiwi mod 11
Dim strverifycode
Strverifycode = arrverifycode (modvalue)
Ai = ai & strverifycode
Checkidcard = ai' finally obtains the 18-digit ID card number
If Len (strnumber) = 18 and strnumber <> AI then
Checkidcard = "Incorrect ID card number! "
Exit Function
End if
End Function