程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 18位SFZ驗證方法

18位SFZ驗證方法

編輯:.NET實例教程

相關鏈接:


  • .Net 15位SFZ升級到18位的算法

  • 18位SFZ驗證方法

    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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved