本帖最后由 zch11230 于 2012-3-23 22:46 编辑
反正身份证号码中的数字都是18位 而且生日都是从第7位开始
$str = "34052419800101001X"
$Bday = StringRegExp($str, '\d{6}(\d{4})(\d{2})(\d{2})\d+', 3)
If StringRight($str, 1) = _checkCode(StringLeft($str, 17)) Then
MsgBox(0, "出生年月日为:", $Bday[0] & "年" & $Bday[1] & "月" & $Bday[2] & "日")
Else
MsgBox (0,"提示","身份证号码有误,请检查")
EndIf
Func _checkCode($no17) ;no17是身份证号前17位.
$wi = "7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2"
$wiarr = StringSplit($wi, " ")
$no17arr = StringSplit($no17, '')
Dim $sum, $a
$sum = 0
For $a = 1 To 17
$sum += $wiarr[$a] * $no17arr[$a]
Next
$mod = Mod($sum, 11)
Dim $checkxy[11] = ['1', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2']
Return $checkxy[$mod]
EndFunc ;==>_checkCode
搜的论坛资料 发在这里当给自己备个份
如果是手输入的身份证号码 还可以先判断号码是否合法再进行操作 对excel的操作我还没有接触 有空了解一下 |