18位身份证验证方法

相关链接:

Private Function CheckCidInfo(ByVal cid As String) As String

Dim aCity() As String = {"", "", "", "", "", "", "", "", "", "", _

"", "北京", "天津", "河北", "山西", "内蒙古", "", _

"", "", "", "", "辽宁", "吉林", "黑龙江", "", "", _

"", "", "", "", "", "上海", "江苏", "浙江", "安微", _

"福建", "江西", "山东", "", "", "", "河南", "湖北", _

"湖南", "广东", "广西", "海南", "", "", "", "重庆", _

"四川", "贵州", "云南", "西藏", "", "", "", "", "", _

"", "陕西", "甘肃", "青海", "宁夏", "新疆", "", "", _

"", "", "", "台湾", "", "", "", "", "", "", "", "", _

"", "香港", "澳门", "", "", "", "", "", "", "", "", "国外"}

Dim iSum As Double = 0

Dim info As String = ""

Dim rg As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("^/d{17}(/d|x)$")

Dim mc As System.Text.RegularExpressions.Match = rg.Match(cid)

If mc.Success = False Then

Return ""

End If

cid = cid.ToLower

cid = cid.Replace("x", "a")

If aCity(Integer.Parse(cid.Substring(0, 2))) = "" Then

Return "非法地址"

End If

Try

DateTime.Parse(cid.Substring(6, 4) & "-" & cid.Substring(10, 2) & "-" & cid.Substring(12, 2))

Catch ex As Exception

Return "非法生日"

End Try

Dim i As Integer

For i = 17 To 0 Step -1

iSum = iSum + (System.Math.Pow(2, i) Mod 11) * Integer.Parse(cid.Substring(17 - i, 1), System.Globalization.NumberStyles.HexNumber)

'

Next

If iSum Mod 11 <> 1 Then

Return "非法证号"

End If

Dim strSex As String

If (Integer.Parse(cid.Substring(16, 1)) Mod 2) = 1 Then

strSex = ""

Else

strSex = ""

End If

Return aCity(Integer.Parse(cid.Substring(0, 2))) & "," & cid.Substring(6, 4) & "-" & cid.Substring(10, 2) & "-" & cid.Substring(12, 2) & "," & strSex

End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值