Asp ID card verification code Function

Source: Internet
Author: User

ID card verification code Function

Function CheckCardId (e)

ArrVerifyCode = Split (", 0, x, 9, 8 ",",")

Wi = Split ",",")

Checker = Split (", 1 ",",")

If Len (e) <15 Or Len (e) = 16 Or Len (e) = 17 Or Len (e)> 18 Then
CheckCardId = "ID card No. consists of 15 or 18 digits"
CheckCardId = False
Exit Function
End If

Dim Ai
If Len (e) = 18 Then
Ai = Mid (e, 1, 17)
ElseIf Len (e) = 15 Then
Ai = e
Ai = Left (Ai, 6) & "19" & Mid (Ai, 7, 9)
End If
If Not IsNumeric (Ai) Then
CheckCardId = "the last digit of the ID card must be a number! "

Exit Function
End If
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

CheckCardId = "Incorrect ID card! "

Exit Function
End If
If strMonth> 12 Or strDay> 31 Then
CheckCardId = "Incorrect ID card! "

Exit Function
End If
Else
CheckCardId = "Incorrect ID card! "

Exit Function
End If
Dim I, TotalmulAiWi
For I = 0 To 16
TotalmulAiWi = TotalmulAiWi + CInt (Mid (Ai, I + 1, 1) * Wi (I)
Next
Dim modValue
ModValue = TotalmulAiWi Mod 11
Dim strVerifyCode
StrVerifyCode = arrVerifyCode (modValue)
Ai = Ai & strVerifyCode
CheckCardId = Ai

If Len (e) = 18 And e <> Ai Then
CheckCardId = "Incorrect ID number! "
Exit Function
End If
End Function

Response. write CheckCardId ("528337194801020025") ''' I don't know who the ID card is ~~~~~~~~~ Haha

''' If the returned ID card is entered, it indicates that it is correct. Otherwise, an error will be prompted...

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.