ASP如何判断文本框中输入的是正确的身份证号码 具体的js代码和表单处的调用方法
1个回答
2013-10-19
展开全部
18位身份证号检测生日那几位是否日期,通过前17位计算最后的校验位是否准确。下面的函数是用VBA写的,ASP也能用吧。不知是否要相应该做些修改。用于服务器端判断,js代码的话可以根据算法自己写。Function CheckId(id As String)
Dim IdLen
Dim Wi, Yi, Ai(0 To 17)
Dim s, Y, cIdLen = Len(id)If IdLen <> 18 Then
CheckId = False
Exit Function
End IfIf CheckBirthday(id) = False Then
CheckId = False
Exit Function
End If
Wi = Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1)
Yi = Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2")'取得号码
For i = 0 To 17
Ai(i) = Mid(id, i + 1, 1)
Next'计算校验位
s = 0
For i = 0 To 16
s = s + Val(Ai(i)) * Wi(i)
Next
Y = s Mod 11
c = Yi(Y)
'对比校验位
If c = Ai(17) Then
CheckId = True
Else
CheckId = False
End If
End Function Function CheckBirthday(id As String)
Dim IdLen, birthday
IdLen = Len(id)
If IdLen = 15 Then
birthday = "19" + Mid$(id, 7, 6)
Else
birthday = Mid$(id, 7, 8)
End If
CheckBirthday = IsDate(Left(birthday, 4) + "-" + Mid$(birthday, 5, 2) + "-" + Right$(birthday, 2))
End Function
Dim IdLen
Dim Wi, Yi, Ai(0 To 17)
Dim s, Y, cIdLen = Len(id)If IdLen <> 18 Then
CheckId = False
Exit Function
End IfIf CheckBirthday(id) = False Then
CheckId = False
Exit Function
End If
Wi = Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1)
Yi = Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2")'取得号码
For i = 0 To 17
Ai(i) = Mid(id, i + 1, 1)
Next'计算校验位
s = 0
For i = 0 To 16
s = s + Val(Ai(i)) * Wi(i)
Next
Y = s Mod 11
c = Yi(Y)
'对比校验位
If c = Ai(17) Then
CheckId = True
Else
CheckId = False
End If
End Function Function CheckBirthday(id As String)
Dim IdLen, birthday
IdLen = Len(id)
If IdLen = 15 Then
birthday = "19" + Mid$(id, 7, 6)
Else
birthday = Mid$(id, 7, 8)
End If
CheckBirthday = IsDate(Left(birthday, 4) + "-" + Mid$(birthday, 5, 2) + "-" + Right$(birthday, 2))
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询