vb程序中,输入身份证号码判断身份证号正确的程序

 我来答
一念春风十里不如你
2016-06-04 · TA获得超过1536个赞
知道小有建树答主
回答量:2560
采纳率:68%
帮助的人:296万
展开全部
Dim Wi(1 To 18) As Integer '检验码
Private Function SetWi()
Wi(1) = 7
Wi(2) = 9
Wi(3) = 10
Wi(4) = 5
Wi(5) = 8
Wi(6) = 4
Wi(7) = 2
Wi(8) = 1
Wi(9) = 6
Wi(10) = 3
Wi(11) = 7
Wi(12) = 9
Wi(13) = 10
Wi(14) = 5
Wi(15) = 8
Wi(16) = 4
Wi(17) = 2
Wi(18) = 1
End Function
Public Function CheckCIDC15(ByVal StrID15 As String) As String
If Not IsNumeric(StrID15) Then
CheckCIDC15 = "身份证号码输入有误!有非数字出现!"
Exit Function
End If
If StrID15 = "111111111111111" Then
CheckCIDC15 = "身份证号码输入错误"
Exit Function
End If
If Val(Mid(StrID15, 9, 2)) < 1 Or Val(Mid(StrID15, 9, 2)) > 12 Then
CheckCIDC15 = "身份证号码输入有误!月份不正确!"
Exit Function
End If
If Val(Mid(StrID15, 11, 2)) < 1 Or Val(Mid(StrID15, 11, 2)) > 31 Then
CheckCIDC15 = "身份证号码输入有误!日期不正确!"
Exit Function
Else
If (Val(Mid(StrID15, 9, 2)) = 4 Or Val(Mid(StrID15, 9, 2)) = 6 Or Val(Mid(StrID15, 9, 2)) = 9 Or Val(Mid(StrID15, 9, 2)) = 11) And Val(Mid(StrID15, 11, 2)) = 31 Then
CheckCIDC15 = "身份证号码输入有误!月份和日期不匹配"
Exit Function
ElseIf Val(Mid(StrID15, 9, 2)) = 2 And (Val(Mid(StrID15, 11, 2)) = 30 Or Val(Mid(StrID15, 11, 2)) = 31) Then
CheckCIDC15 = "身份证号码输入有误!2月份没有" & Val(Mid(StrID15, 11, 2)) & "天"
Exit Function
End If
End If
End Function
Public Function CheckCIDC18(ByVal StrID18 As String) As String
Dim StrID17 As String, AiWi As Integer, num As Integer, A18 As String
SetWi
If Not IsNumeric(Left(StrID18, 17)) Then
CheckCIDC18 = "身份证号码输入有误!"
Exit Function
End If
If Val(Mid(StrID18, 11, 2)) < 1 Or Val(Mid(StrID18, 11, 2)) > 12 Then
CheckCIDC18 = "身份证号码输入有误!月份不正确!"
Exit Function
End If
If Val(Mid(StrID18, 13, 2)) < 1 Or Val(Mid(StrID18, 13, 2)) > 31 Then
CheckCIDC18 = "身份证号码输入有误!" & vbCrLf & "日期不正确!"
Exit Function
Else
If (Val(Mid(StrID18, 11, 2)) = 4 Or Val(Mid(StrID18, 11, 2)) = 6 Or Val(Mid(StrID18, 11, 2)) = 9 Or Val(Mid(StrID18, 11, 2)) = 11) And Val(Mid(StrID18, 13, 2)) = 31 Then
CheckCIDC18 = "身份证号码输入有误!月份和日期不匹配"
Exit Function
ElseIf Val(Mid(StrID18, 11, 2)) = 2 And (Val(Mid(StrID18, 13, 2)) = 30 Or Val(Mid(StrID18, 13, 2)) = 31) Then
CheckCIDC18 = "身份证号码输入有误!2月份没有" & Val(Mid(StrID18, 13, 2)) & "天"
Exit Function
End If
End If
StrID17 = Left(StrID18, 17)
AiWi = 0
For num = 1 To 17
AiWi = AiWi + Val(Mid(StrID17, num, 1)) * Wi(num)
Next num
Select Case AiWi Mod 11
Case 0
A18 = "1"
Case 1
A18 = "0"
Case 2
A18 = "X"
Case 3
A18 = "9"
Case 4
A18 = "8"
Case 5
A18 = "7"
Case 6
A18 = "6"
Case 7
A18 = "5"
Case 8
A18 = "4"
Case 9
A18 = "3"
Case 10
A18 = "2"
End Select
If A18 <> Right(StrID18, 1) Then
CheckCIDC18 = "身份证号码输入有误!" '尾数检验马不正确"
Exit Function
End If
End Function
Public Function CIDC15To18(ByVal StrID15 As String) As String
SetWi
Dim StrID17 As String, StrID18 As String, num As Integer, AiWi As Integer
If Not IsNumeric(StrID15) Then
CIDC15To18 = "15位身份证号码输入有误!" & vbCrLf & "有非数字出现!"
Exit Function
End If
If Val(Mid(StrID15, 9, 2)) < 1 Or Val(Mid(StrID15, 9, 2)) > 12 Then
CIDC15To18 = "身份证号码输入有误!" & vbCrLf & "月份不正确!"
Exit Function
End If
If Val(Mid(StrID15, 11, 2)) < 1 Or Val(Mid(StrID15, 11, 2)) > 31 Then
CIDC15To18 = "身份证号码输入有误!" & vbCrLf & "日期不正确!"
Exit Function
Else
If (Val(Mid(StrID15, 9, 2)) = 4 Or Val(Mid(StrID15, 9, 2)) = 6 Or Val(Mid(StrID15, 9, 2)) = 9 Or Val(Mid(StrID15, 9, 2)) = 11) And Val(Mid(StrID15, 11, 2)) = 31 Then
CIDC15To18 = "身份证号码输入有误!" & vbCrLf & "月份和日期不匹配"
Exit Function
ElseIf Val(Mid(StrID15, 9, 2)) = 2 And (Val(Mid(StrID15, 11, 2)) = 30 Or Val(Mid(StrID15, 11, 2)) = 31) Then
CIDC15To18 = "身份证号码输入有误!" & vbCrLf & "2月份没有" & Val(Mid(StrID15, 11, 2)) & "天"
Exit Function
End If
End If
StrID17 = Left(StrID15, 6) & "19" & Right(StrID15, 9)
AiWi = 0
For num = 1 To 17
AiWi = AiWi + Val(Mid(StrID17, num, 1)) * Wi(num)
Next num
Select Case AiWi Mod 11
Case 0
StrID18 = StrID17 & "1"
Case 1
StrID18 = StrID17 & "0"
Case 2
StrID18 = StrID17 & "X"
Case 3
StrID18 = StrID17 & "9"
Case 4
StrID18 = StrID17 & "8"
Case 5
StrID18 = StrID17 & "7"
Case 6
StrID18 = StrID17 & "6"
Case 7
StrID18 = StrID17 & "5"
Case 8
StrID18 = StrID17 & "4"
Case 9
StrID18 = StrID17 & "3"
Case 10
StrID18 = StrID17 & "2"
End Select
CIDC15To18 = StrID18
End Function
'身份证检验函数,如果有错误,则弹出正确信息,若正确,则继续执行
Function CIDCheck(strId As String) As String
If Len(strId) = 15 Then
CIDCheck = CheckCIDC15(strId)
ElseIf Len(strId) = 18 Then
CIDCheck = CheckCIDC18(strId)
Else
CIDCheck = "身份证位数不对"
End If
End Function
华视电子读写设备公司
2024-11-07 广告
台式居民身份证阅读机具使用可以免费咨询华视电子,居民身份证阅读机具专为各有关部门方便身份证信息读取和查验而开发的一款可移动设备。华视电子的该设备符合ISO14443 Type B国际标准,配备高性能PDA作为服务终端,与蓝牙阅读器通过蓝牙连... 点击进入详情页
本回答由华视电子读写设备公司提供
施远板婵
游戏玩家

2019-08-22 · 游戏我都懂点儿,问我就对了
知道大有可为答主
回答量:1.4万
采纳率:32%
帮助的人:810万
展开全部
dim
s
as
string,y
as
string
i
as
long
s=xxxxxx19920315xxxx
y=mid(s,7,4)
从身份证的第七位取4个
i=year(now())-val(y)+1
now()函数是获得现在的电脑的时间,year是把now的年份取出,val是把字符串转换成数字,因为刚生下来就是1岁所以要加1
msgbox
i
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式