|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Public Function sfzjy(sid, xb) ' As Currency
'1、身份证不满15位,2、性别与身份证不符,3、出生月份出错(不在1-12)
'4、出生日期出错(不在1-31范围内),5、18位校验位出错,6、18位身份证年份出借
On Error Resume Next
Dim s1, s2, jym, x
If xb = 1 Then x = 1
If xb = "男" Then x = 1
If xb = 2 Then x = 0
If xb = "女" Then x = 0
s1 = " 7 910 5 8 4 2 1 6 3 7 910 5 8 4 2"
s2 = "10x98765432"
If Len(sid) <> 15 And Len(sid) <> 18 Then
sfzjy = "身份证位数错误"
'测试15位身份证的信息
ElseIf Len(sid) = 15 And Val(Mid(sid, 7, 2)) < 10 Then
sfzjy = "年龄好大,请多多保重!"
ElseIf Len(sid) = 15 And Val(Mid(sid, 9, 2)) > 12 Then
sfzjy = "出生月份错误!"
ElseIf Len(sid) = 15 And Val(Mid(sid, 11, 2)) > 31 Then
sfzjy = "出生日期错误!"
ElseIf Len(sid) = 15 And Mid(sid, 15, 1) Mod 2 <> x Then
sfzjy = "性别错误!"
ElseIf Len(sid) = 15 Then
newid = Left(sid, 6) + "19" + Right(sid, 9)
jym = 0
For i = 1 To 17
jym = jym + Val(Mid(s1, i * 2 - 1, 2)) * Val(Mid(newid, i, 1))
Next i
sfzjy = newid + Mid(s2, jym Mod 11 + 1, 1)
'测试18位身份证的信息
ElseIf Len(sid) = 18 And Val(Mid(sid, 7, 2)) <> 19 Then
sfzjy = "出生年错误!"
ElseIf Len(sid) = 18 And Val(Mid(sid, 9, 2)) < 10 Then
sfzjy = "年龄好大,请多多保重!"
ElseIf Len(sid) = 18 And Val(Mid(sid, 11, 2)) > 12 Then
sfzjy = "出生月份错误!"
ElseIf Len(sid) = 18 And Val(Mid(sid, 13, 2)) > 31 Then
sfzjy = "出生日期错误!"
ElseIf Len(sid) = 18 And Mid(sid, 17, 1) Mod 2 <> x Then
sfzjy = "性别错误!"
Else
newid = Left(sid, 17)
jym = 0
For i = 1 To 17
jym = jym + Val(Mid(s1, i * 2 - 1, 2)) * Val(Mid(newid, i, 1))
Next i
If Mid(s2, jym Mod 11 + 1, 1) <> Mid(sid, 18, 1) Then
sfzjy = "识别码错,应为:" & Mid(s2, jym Mod 11 + 1, 1)
Else
sfzjy = sid
End If
End If
End Function |
|