我现在只是自己编写了验证17位身份证号码的函数,那么如何同时验证15位的?18位的?请各位帮忙!
解决方案 »
- div在firefox中如何分层。
- gridview中使用itemplate中的自定义控件为什么在postback后控件没有了
- 急啊,请教一个Ajax刷新的问题!
- 奇怪的问题:DataGrid使用时索引超出范围。必须为非负值并小于集合大小。
- 郁闷一下午 求助--- 提示update语法错误!!!!!!!!!!!!!!!!怎么办
- 小菜一碟——一步一步用c#写论坛,V1.50源代码发布!
- DataGrid
- 编译器错误信息: CS1501: 重载“Directory”方法未获取“1”参数
- 10月1日国庆节是我一生很重要朋友的生日,请大家帮我送一份祝福给她!谢谢!!!
- xsl中有没有数组的概念阿?思归大哥在吗?200分寻求答案阿!
- 请教一问题!
- 有关Session丢失的问题!
Public Shared Function CheckCidInfo(ByVal cid As String) As Boolean
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 False
End If
cid = cid.ToLower
cid = cid.Replace("x", "a")
If aCity(Integer.Parse(cid.Substring(0, 2))) = "" Then
'Return "非法地址"
Return False
End If
Try
DateTime.Parse(cid.Substring(6, 4) & "-" & cid.Substring(10, 2) & "-" & cid.Substring(12, 2))
Catch ex As Exception
'Return "非法生日"
Return False
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 "非法证号"
Return False
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
Return TrueEnd Function
Return False
End If判断18位的:
If mc.Success = False or mc.Length>18 Then
Return False
End If这样你的方法只要再加上一个参数即可完成15、17、18位校验过程:
Public Shared Function CheckCidInfo(ByVal cid As String, ByVal length as integer) As Boolean... Dim rg As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("^\d{" & length.ToString() & "}(\d|x)$")
Dim mc As System.Text.RegularExpressions.Match = rg.Match(cid)
If mc.Success = False or mc.Length > length Then
Return False
End If
...