ID card verification algorithm and ASP program _ Application Skills

Source: Internet
Author: User
18-bit ID card verification algorithm
Verification code algorithm for ID card
ID Check code generation method:
∑ (AIXWI) (mod 11)

I: the number of digits from the to left including the check code;

AI represents the number character value on position I;

The weight factor on the position of Wi, its numerical wi=mod (Power (2, (n-1)), 11)

I 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Wi. 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1

The corresponding check code:
∑ (AIXWI) (mod 11) 0 1 2 3 4 5 6 7 8 9 10
Parity code character value AI 1 0 X 9 8 7 6 5 4 3 2

Here is the checksum function:

FUNCTION sfzjy (num)
If Len (num) =15 Then
CID = Left (num,6) & "&right" (num,9)
ElseIf len (num) =17 or len (num) =18 Then
CID = Left (num,17)
End If
Nsum=mid (cid,1,1) * 7
Nsum=nsum+mid (cid,2,1) * 9
Nsum=nsum+mid (cid,3,1) * 10
Nsum=nsum+mid (cid,4,1) * 5
Nsum=nsum+mid (cid,5,1) * 8
Nsum=nsum+mid (cid,6,1) * 4
Nsum=nsum+mid (cid,7,1) * 2
Nsum=nsum+mid (cid,8,1) * 1
Nsum=nsum+mid (cid,9,1) * 6
Nsum=nsum+mid (cid,10,1) * 3
Nsum=nsum+mid (cid,11,1) * 7
Nsum=nsum+mid (cid,12,1) * 9
Nsum=nsum+mid (cid,13,1) * 10
Nsum=nsum+mid (cid,14,1) * 5
Nsum=nsum+mid (cid,15,1) * 8
Nsum=nsum+mid (cid,16,1) * 4
Nsum=nsum+mid (cid,17,1) * 2
' * Calculate check digit
Check_number=12-nsum MoD 11
If check_number=10 then check_number= "X" elseIf check_number=12 then check_number= "1" elseIf check_number=11 then Check_n umber= "0" End If Sfzjy=check_number
End Function



Other checksums:
Sex and date of birth:

sfznum= ID Number
Lenx=len (Sfznum)
If Lenx=15 Then
Yy= "&mid" (xian,7,2)
Mm=mid (xian,9,2)
Dd=mid (xian,11,2)
Aa=mid (xian,15,1) ' 15 identity card 15th place, divisible by 2 for females

End If
If Lenx=18 Then
Yy=mid (xian,7,4)
Mm=mid (xian,11,2)
Dd=mid (xian,13,2)
Aa=mid (xian,17,1) ' 18 identity card 17th place, divisible by 2 for females
End If
If AA mod 2=0 then
xb= "Female"
Else
xb= "Male"
End If

If Lenx=18 Then
If Mid (xian,18,1) <>cstr (Sfzjy (Xian)) Then ' if the 18th check code does not equal the computed checksum code, the ID number is incorrect.
Response.Write "Hint: ID card check bit error!"
Else
Response.Write "Result: ID card number verified as legal number!"
End If
Else ' If you enter a 15-digit number, the 18-digit new number is calculated
Response.Write "New ID:" &left (xian,6) & "&right" (xian,9) &cstr (Sfzjy (Xian))
End If

Regarding the household registration judgment then wants the database. It's not available here.
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.