图片附件: 游客没有浏览图片的权限,请
登录 或
注册
程序代码:
Dim QYM, SSMC, XX As Integer
Private Sub Command1_Click()
'解析身份证
If Not Len(Text1.Text) = 18 Then
MsgBox "对不起!二代身份证号码必须是18各数字或17各数字加一个字母组成!", 16, "身份证位数不对!"
Exit Sub
End If
If IsNumeric(Left(Text1.Text, 17)) = False Then
MsgBox "对不起!二代身份证号码的前17位必须是数字!", 16, "身份证的前17位不能有其他字符!"
Exit Sub
End If
Dim CSHN As String, CSHY As String, CSHR As String, NL As Integer, XB As String, XBX As String, SHF1 As String, SHF2 As String, SFZH As String, CSNYR As String
SFZH = Text1.Text
SHF1 = Left(SFZH, 2) '身份证的前二位是省份代码,必须在 QYM 数组内,否则检测不多省份
CSHN = Mid(SFZH, 7, 4)
If Val(CSHN) > Year(Date) Or Val(CSHN) < Year(Date) - 150 Then '这个150是最大的极限年龄
MsgBox "错误!身份证的年份不在居民生存年份范围!", 16, "提示!"
Exit Sub
End If
CSHY = Mid(SFZH, 11, 2)
If Val(CSHY) > 12 Or Val(CSHY) < 1 Then
MsgBox "错误!身份证的月份不在月份范围!", 16, "提示!"
Exit Sub
End If
CSHR = Mid(SFZH, 13, 2)
If Val(CSHR) > 31 Or Val(CSHR) < 1 Then
MsgBox "错误!身份证的日子不在日子范围!", 16, "提示!" '这里没有检测大月、小月及二月的具体日期检测,例如大月=31,小月=30,二月=28或29,这个检测你自己完成吧
Exit Sub
End If
CSNYR = CSHN & "-" & CSHY & "-" & CSHR
NL = DateDiff("YYYY", CDate(CSNYR), Date)
XB = Mid(SFZH, 17, 1)
If Val(XB) Mod 2 = 0 Then
XBX = "女"
Else
XBX = "男"
End If
For I = 0 To XX
If SHF1 = QYM(I) Then SHF2 = SSMC(I)
Next I
Text2(0).Text = CSNYR: Text2(1).Text = NL: Text2(2).Text = XBX: Text2(3).Text = SHF2
End Sub
Private Sub Form_Load()
QYM = Array("11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35", "36", "37", "41", "42", "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63", "64", "65")
SSMC = Array("北京市", "天津市", "河北省", "山西省", "内蒙古自治区", "辽宁省", "吉林省", "黑龙江省", "上海市", "江苏省", "浙江省", "安徽省", "福建省", "江西省", "山东省", "河南省", "湖北省", "湖南省", "广东省", "广西壮族自治区", "海南省", "重庆市", "四川省", "贵州省", "云南省", "西藏自治区", "陕西省", "甘肃省", "青海省", "宁夏回族自治区", "新疆维吾尔自治区")
XX = UBound(QYM)
End Sub
这个是否符合你的要求,是我以前做的,找出来给你参考。