'函数名称: IsIDNumber
'功能描述: 根据GB11643-1999编码规则验证18位身份证号码是否有效
'输入参数: 参数1:IDNumber 必需的,18位身份证号码
'返回参数: 有效返回True,无效返回False
'兼 容 性:
'使用示例: IsIDNumber("370284197901130819") '返回True
'相关调用:
'作 者: 红尘如烟
'创建日期: 20010-4-25
'===================================================================
Function IsIDNumber(ByVal IDNumber As String) As Boolean
Const W As String = "79058421637905842" '加权因子
Const C As String = "10X98765432" '校验码
Dim S As Integer, i As Integer, T As Integer
IDNumber = UCase(Trim(IDNumber))
If Len(IDNumber) <> 18 Then Exit Function
If Not IsNumeric(Mid(IDNumber, 1, 17)) Then Exit Function
If Not IDNumber Like "*[0-9X]" Then Exit Function
For i = 1 To 17
T = Mid(W, i, 1)
If T = 0 Then T = 10
S = S + Mid(IDNumber, i, 1) * T
Next
T = S Mod 11
If Right(IDNumber, 1) = Mid(C, T + 1, 1) Then IsIDNumber = True
End Function