/******************************************************************************/ //函数名: gf_CIDCheck //功能说明:验证身份证 //输入参数:1、as_strid 输入的身份证号码 //返回值: 0=正常;1=失败 //函数完成:woods /******************************************************************************/ integer wi[1 to 18]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1} //校验码
//判断身份证是15或18位 If Len(strId) = 15 Then If Not isNumber(strid) Then messagebox("提示","身份证号码输入有误!有非数字出现!" ) return 1 End If If integer(Mid(strid, 9, 2)) < 1 Or integer(Mid(strid, 9, 2)) > 12 Then messagebox("提示","身份证号码输入有误!月份不正确!" ) return 1 End If If integer(Mid(strid, 11, 2)) < 1 Or integer(Mid(strid, 11, 2)) > 31 Then messagebox("提示","身份证号码输入有误!日期不正确!" ) return 1 Else If (integer(Mid(strid, 9, 2)) = 4 Or integer(Mid(strid, 9, 2)) = 6 Or integer(Mid(strid, 9, 2)) = 9 Or integer(Mid(strid, 9, 2)) = 11) And integer(Mid(strid, 11, 2)) = 31 Then messagebox("提示","身份证号码输入有误!月份和日期不匹配!" ) return 1 ElseIf integer(Mid(strid, 9, 2)) = 2 And (integer(Mid(strid, 11, 2)) = 30 Or integer(Mid(strid, 11, 2)) = 31) Then messagebox("提示","身份证号码输入有误!2月份没有" + (Mid(strid, 11, 2)) + "天!" ) return 1 End If End If ElseIf Len(strId) = 18 Then string StrID17,A18 integer AiWi, num If Not isNumber(Left(strid, 17)) Then messagebox("提示","身份证号码输入有误!" ) return 1 End If If integer(Mid(strid, 11, 2)) < 1 Or integer(Mid(strid, 11, 2)) > 12 Then messagebox("提示","身份证号码输入有误!月份不正确!" ) return 1 End If If integer(Mid(strid, 13, 2)) < 1 Or integer(Mid(strid, 13, 2)) > 31 Then messagebox("提示","身份证号码输入有误!日期不正确!" ) return 1 Else If (integer(Mid(strid, 11, 2)) = 4 Or integer(Mid(strid, 11, 2)) = 6 Or integer(Mid(strid, 11, 2)) = 9 Or integer(Mid(strid, 11, 2)) = 11) And integer(Mid(strid, 13, 2)) = 31 Then messagebox("提示","身份证号码输入有误!月份和日期不匹配!" ) return 1 ElseIf integer(Mid(strid, 11, 2)) = 2 And (integer(Mid(strid, 13, 2)) = 30 Or integer(Mid(strid, 13, 2)) = 31) Then messagebox("提示","身份证号码输入有误!2月份没有" + (Mid(strid, 13, 2)) + "天!" ) return 1 End If End If StrID17 = Left(strid, 17) AiWi = 0 For num = 1 To 17 AiWi = AiWi + integer(Mid(StrID17, num, 1)) * Wi[num] Next choose Case Mod(AiWi,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 choose If A18 <> Right(strid, 1) Then messagebox("提示","身份证号码输入有误!尾数校验码不正确!") return 1 End If Else messagebox("提示","身份证位数不对!" ) return 1 End If
return 0