Foxtable(狐表)用户栏目专家坐堂 → ValidPIN代码不支持15位的身份证号码怎么办?(自己解决了)


  共有11132人关注过本帖树形打印复制链接

主题:ValidPIN代码不支持15位的身份证号码怎么办?(自己解决了)

帅哥哟,离线,有人找我吗?
pc005637
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1039 积分:12926 威望:0 精华:0 注册:2011/5/29 15:19:00
ValidPIN代码不支持15位的身份证号码怎么办?(自己解决了)  发帖心情 Post By:2012/11/28 9:45:00 [只看该作者]

只支持18位的新身份证号码,但是有些老人只有第一代的身份证

 

在窗口中的身份证的文本输入框,DataParse代码输入:

 

If e.Value IsNot Nothing Then
    Dim d As String = e.Value
    If ValidPIN(d) = False Then
        If d.Length = 15 Then
            d = d.Insert(6,"19")
            Dim str0,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16 As String
            Dim Int0,Int1,Int2,Int3,Int4,Int5,Int6,Int7,Int8,Int9,Int10,Int11,Int12,Int13,Int14,Int15,Int16 As Integer
            str0 = d.Chars(0)
            If Integer.TryParse(str0, Int0) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str1 = d.Chars(1)
            If Integer.TryParse(str1, Int1) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str2 = d.Chars(2)
            If Integer.TryParse(str2, Int2) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str3 = d.Chars(3)
            If Integer.TryParse(str3, Int3) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str4 = d.Chars(4)
            If Integer.TryParse(str4, Int4) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str5 = d.Chars(5)
            If Integer.TryParse(str5, Int5) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str6 = d.Chars(6)
            If Integer.TryParse(str6, Int6) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str7 = d.Chars(7)
            If Integer.TryParse(str7, Int7) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str8 = d.Chars(8)
            If Integer.TryParse(str8, Int8) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str9 = d.Chars(9)
            If Integer.TryParse(str9, Int9) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str10 = d.Chars(10)
            If Integer.TryParse(str10, Int10) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str11 = d.Chars(11)
            If Integer.TryParse(str11, Int11) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str12 = d.Chars(12)
            If Integer.TryParse(str12, Int12) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str13 = d.Chars(13)
            If Integer.TryParse(str13, Int13) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str14 = d.Chars(14)
            If Integer.TryParse(str14, Int14) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str15 = d.Chars(15)
            If Integer.TryParse(str15, Int15) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
            str16 = d.Chars(16)
            If Integer.TryParse(str16, Int16) = False Then
                MessageBox.Show("输入的身份证号码含非法字符!")
                Return
            End If
           
            Dim r,m As Integer
            Dim n As String
            r = Int0 * 7 + Int1 * 9 + Int2 * 10 + Int3 * 5 + Int4 * 8 + Int5 * 4 + Int6 * 2 + Int7 * 1 + Int8 * 6 + Int9 * 3 + Int10 * 7 + Int11 * 9 + Int12 * 10 + Int13 * 5 + Int14 * 8 + Int15 * 4 + Int16 * 2
            m = r Mod 11
            Select Case m
                Case 0
                    n = "1"
                Case 1
                    n = "0"
                Case 2
                    n = "X"
                Case 3
                    n = "9"
                Case 4
                    n = "8"
                Case 5
                    n = "7"
                Case 6
                    n = "6"
                Case 7
                    n = "5"
                Case 8
                    n = "4"
                Case 9
                    n = "3"
                Case 10
                    n = "2"
            End Select
            d = d & n
            e.Value = d
        Else
            MessageBox.Show("输入的身份证号码不是15位!")
        End If
    End If
End If

 

自动将15位身份证号码,转换成18位号码。

请各位大神,精简一下代码。附上 二代居民身份证验证码计算原理.doc

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:二代居民身份证验证码计算原理.rar

[此贴子已经被作者于2012-11-28 17:12:37编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
lin_hailun
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2012/11/28 9:49:00 [只看该作者]

 可以自己写一个,或者对15位的转换一下,升级到18位。

以下是引用明丰在2012-11-10 10:37:00的发言:

身份证号码15位、18位可以同时输入了,请各位测试。

 

'表属性-数据-DataColChanged
If e.DataCol.Name = "身份证号" Then
    If e.DataRow.IsNull("身份证号") Then
        e.DataRow("密码") = Nothing
    Else
        Dim d As String = e.DataRow("身份证号")
        For i As Integer = 0 To d.Length - 1
            If Char.IsLetterOrDigit(d.Chars(i)) = False Then
                Messagebox.Show("身份证号码不正确!")
                e.DataRow("密码") = Nothing
                Return
            End If
        Next
        Dim r2,r3,r4,r5 As String
        If d.length = 15 Then
            Dim r1 As String = d.Substring(6,2)
            If r1 = "00" Then
            Else
                d = d.Insert(6,"19")
                r2 = StrReverse(d)
                For i As Integer = 17 To 1 Step -1
                    r3 = r2.Chars(i-1)
                    r4 = r4 + ( r3 * ((2 ^ i) Mod 11 )) '加权因子
                Next
            End If
            r4 = r4 Mod 11
            If r4 = "0" Then
                r4 = "1"
            ElseIf r4 = "1" Then
                r4 = "0"
            ElseIf r4 = "2" Then
                r4 = "X"
            ElseIf r4 = "3" Then
                r4 = "9"
            ElseIf r4 = "4" Then
                r4 = "8"
            ElseIf r4 = "5" Then
                r4 = "7"
            ElseIf r4 = "6" Then
                r4 = "6"
            ElseIf r4 = "7" Then
                r4 = "5"
            ElseIf r4 = "8" Then
                r4 = "4"
            ElseIf r4 = "9" Then
                r4 = "3"
            ElseIf r4 = "10" Then
                r4 = "2"
            End If
            r5 = d.SubString(d.length - 6,6) '6位密码
            d = d & r4 '15位升18位
        End If
       
        If ValidPIN(d) Then
            If r5 Is Nothing Then
                d = right(d,6)
            Else
                d = r5
            End If
            e.DataRow("密码") = d
        Else
            messagebox.show("身份证号码不正确!")
            e.DataRow("密码") = Nothing
        End If
    End If
End If



 回到顶部