Code to verify that the ID number is correct using ASP

Source: Internet
Author: User
Tags date copy split trim

This article is not original, but only a combination of two or three articles sorted together.

If we want to verify the correct ID number, we must first understand the meaning of the ID number.

What does the ID number mean?

1, the structure of the number
The citizenship number is a characteristic combination code, which consists of a 17 digit ontology code and a check code. The order is from left to right: six digit address code, eight digit birth date code, three digit sequential code and one digit parity code.

2, address code (top six digits)
The administrative division code of the county (city, Flag, district) of the resident account of the encoding object is executed according to the GB/T2260 regulations.

3, Birth date code (seventh to 14 digits)
Indicates the year, month, and day of the encoding object's birth, which is executed according to gb/t7408, and the year, month, and day codes are not separated by delimiters.

4. Sequence code (15th to 17 digits)
Indicates the sequence number assigned to a person born in the same same address code, the same month and the same day, and the odd distribution of order codes to men, even to females.

5, check code (18th digits)
(1) The weighted summation formula of 17-digit body code
S = SUM (Ai * Wi), i = 0, ..., 16, first the sum of the first 17 digits
Ai: Indicates the ID number value of position I
Wi: A weighted factor representing position I
Wi:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4-2
(2) Computational model
Y = mod (S, 11)
(3) The corresponding check code is obtained through the model
Y:0 1 2 3 4 5 6 7 8 9 10
Check code: 1 0 X 9 8 7 6 5 4 3 2

So we can basically write a function to check if it's correct.

Verify ID number ASP code functions are as follows

Code Copy Box

Function Idcheck (e) Idcheck = Truearrverifycode = Split ("1,0,x,9,8,7,6,5,4,3,2", ",") Wi = Split (" 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 ",", ") Checker = Split (" 1,9,8,7,6,5,4,3,2,1,1 ",", ") If Len (E) < or Len (e) = Len (e) = 15 or Len (e) > Then ' idcheck= "have a total number of 18 digits" Idcheck = Falseexit functionend ifdim Len (e) = Aiif i = Mid (e, 1) ElseIf Len (e) = Thenai = EAi = Left (AI, 6) & "D" & Mid (AI, 7, 9) End IfIf not IsNumeric (AI) Th En ' idcheck= ' ID card except the last one, must be a number! "Idcheck = Falseexit functionend Ifdim stryear, strmonth, strdaystryear = CInt (Mid (AI, 7, 4)) Strmonth = CInt (Mid (AI, 11, 2 ) Strday = CInt (Mid (Ai, 2)) Birthday = Trim (stryear) + "-" + trim (strmonth) + "-" + trim (strday) If IsDate (birthday) NIf DateDiff ("yyyy", now,birthday) <-140 or CDate (birthday) >date () Then ' idcheck= ' identity card input Error! "Idcheck = falseexit functionend ifif strmonth > Or strday > Thenidcheck = False ' idcheck=" ID card input Error! "Exit functionend ifelse ' idcheck=" ID card input Error! "Idcheck = FalseeXIT functionend Ifdim I, totalmulaiwifor i = 0 to 16TotalmulAiWi = Totalmulaiwi + CInt (Mid (Ai, i + 1, 1)) * Wi (i) Nextdim m Odvaluemodvalue = Totalmulaiwi Mod 11Dim strverifycodestrverifycode = Arrverifycode (modvalue) ai = ai & Strverifycodei Dcheck = Aiif Len (e) = e <> Ai Then ' idcheck= ' ID number input Error! "Idcheck = falseexit functionend IfEnd Function


[Ctrl + a All select and copy]

In addition, if can combine the user fills in the area, the birthday, does the related verification, that is more perfect. There is basically no way to fill in the wrong number. Ha ha. Except to fill in the exact information and ID number of someone else,



Related Article

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.