身份证验证

原创 2007年09月26日 14:06:00
Public Class clsCheckId
    
Public dateId18 As Date
    
Public dateId15 As Date
    
Public errMessage As String
    
Public blnSex As Boolean

    
Public Function ChechPersonID(ByVal strIdNo As StringByVal blnIDlength As BooleanByVal blnWhichOccur As BooleanAs Boolean
        
'blnIDlength 为TRUE 是  为检测18身份证 否则  检测15位身份证       blnWhichOccur 为TRUE时 在change事件中发生 否则 在 leave事件中发生
        Select Case blnWhichOccur      'change事件中
            Case True    'change事件中发生
                If blnIDlength = True Then     '18
                    If strIdNo.Trim.Length = 0 Then Exit Function
                    strIdNo 
= Microsoft.VisualBasic.Left(strIdNo, 17)          '检测格式 是否含有不规范字符
                    If Not IsNumeric(strIdNo) Then
                        errMessage 
= "输入格式不正确"
                        
Exit Function
                        
Return False
                    
Else
                        
Return True
                    
End If
                
End If
                
If blnIDlength = False Then    ' 15位
                    If strIdNo.Trim.Length = 0 Then Exit Function
                    
'strIdNo = Microsoft.VisualBasic.Left(strIdNo, 15)
                    If Not IsNumeric(strIdNo) Then   '输入位数和格式
                        errMessage = "输入格式不正确"
                        
Exit Function
                        
Return False
                    
Else
                        
Return True
                    
End If
                
End If
            
Case False   'leave   事件              
                '选中18位
                Dim intSex As Integer 'sex
                If blnIDlength = True Then
                    intSex 
= CInt(Mid(strIdNo, strIdNo.Length - 11))
                    
If intSex = 1 Or intSex = 3 Or intSex = 5 Or intSex = 7 Or intSex = 9 Then
                        blnSex 
= True
                    
Else
                        blnSex 
= False
                    
End If
                    
'返回生日
                    If strIdNo.Length <> 18 Then
                        errMessage 
= "身份证位数不正确"
                        
Exit Function
                        
Return False
                    
Else
                        
Dim strYear As String = Mid(strIdNo, 74)
                        
Dim strMonth As String = Mid(strIdNo, 112)
                        
Dim strDay As String = Mid(strIdNo, 132)
                        
Dim isRunNian As Integer = (strYear Mod 4)
                        
If CInt(strYear) > 1901 And CInt(strYear) < 2050 And CInt(strMonth) <= 12 And CInt(strMonth) > 0 And CInt(strDay) > 0 Then
                            
Select Case isRunNian
                                
Case 0
                                    
If strMonth = 1 Or strMonth = 3 Or strMonth = 5 Or strMonth = 7 Or strMonth = 8 Or strMonth = 10 Or strMonth = 12 Then               '全部是错误的!!!!
                                        If strDay > 31 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId18 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + strYear))
                                            
Return True
                                        
End If
                                    
ElseIf strMonth = 4 Or strMonth = 6 Or strMonth = 9 Or strMonth = 11 Then             '全部是错误的!!!!
                                        If strDay > 30 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId18 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + strYear))
                                            
Return True
                                        
End If
                                    
Else : strMonth = 2 '闰年29
                                        If strDay > 29 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId18 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + strYear))
                                            
Return True
                                        
End If
                                    
End If
                                
Case Else
                                    
If strMonth = 1 Or strMonth = 3 Or strMonth = 5 Or strMonth = 7 Or strMonth = 8 Or strMonth = 10 Or strMonth = 12 Then               '全部是错误的!!!!
                                        If strDay > 31 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId18 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + strYear))
                                            
Return True
                                        
End If
                                    
ElseIf strMonth = 4 Or strMonth = 6 Or strMonth = 9 Or strMonth = 11 Then             '全部是错误的!!!!
                                        If strDay > 30 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId18 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + strYear))
                                            
Return True
                                        
End If
                                    
Else : strMonth = 2 '闰年29
                                        If strDay > 28 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId18 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + strYear))
                                            
Return True
                                        
End If
                                    
End If
                            
End Select
                        
Else                                      '不在正确年里面
                            errMessage = "身份证日期错误"
                        
End If
                    
End If
                
ElseIf blnIDlength = False Then       '15位身份证

                    intSex 
= Microsoft.VisualBasic.Right(strIdNo, 1)
                    
If intSex = 1 Or intSex = 3 Or intSex = 5 Or intSex = 7 Or intSex = 9 Then
                        blnSex 
= True
                    
Else
                        blnSex 
= False
                    
End If

                    
If strIdNo.Length <> 15 Then
                        errMessage 
= "身份证位数不正确"
                        
Exit Function
                        
Return False
                    
Else
                        
Dim strYear As String = Mid(strIdNo, 72)
                        
Dim strYear2 As String = "19" + strYear
                        
Dim strMonth As String = Mid(strIdNo, 92)
                        
Dim strDay As String = Mid(strIdNo, 112)
                        
Dim isRunNian As Integer = (CInt(strYear) Mod 4)
                        
If strYear2 > 1901 And strYear2 < 1999 And CInt(strMonth) <= 12 And CInt(strMonth) > 0 And CInt(strDay) > 0 Then
                            
Select Case isRunNian
                                
Case 0
                                    
If strMonth = 1 Or strMonth = 3 Or strMonth = 5 Or strMonth = 7 Or strMonth = 8 Or strMonth = 10 Or strMonth = 12 Then               '全部是错误的!!!!
                                        If strDay > 31 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId15 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + "19" + strYear))
                                            
Return True
                                        
End If

                                    
ElseIf strMonth = 4 Or strMonth = 6 Or strMonth = 9 Or strMonth = 11 Then             '全部是错误的!!!!
                                        If strDay > 30 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId15 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + "19" + strYear))
                                            
Return True
                                        
End If
                                    
Else
                                        
If strDay > 29 Then           '闰年29
                                            errMessage = "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId15 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + "19" + strYear))
                                            
Return True
                                        
End If
                                    
End If

                                
Case Else
                                    
If strMonth = 1 Or strMonth = 3 Or strMonth = 5 Or strMonth = 7 Or strMonth = 8 Or strMonth = 10 Or strMonth = 12 Then               '全部是错误的!!!!
                                        If strDay > 31 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId15 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + "19" + strYear))
                                            
Return True
                                        
End If

                                    
ElseIf strMonth = 4 Or strMonth = 6 Or strMonth = 9 Or strMonth = 11 Then             '全部是错误的!!!!
                                        If strDay > 30 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId15 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + "19" + strYear))
                                            
Return True
                                        
End If
                                    
ElseIf strMonth = 2 Then
                                        
If strDay > 28 Then
                                            errMessage 
= "身份证日期错误"
                                            
Return False
                                        
Else
                                            dateId15 
= DateTime.Parse(System.String.Concat(strMonth + "," + strDay + "," + "19" + strYear))
                                            
Return True
                                        
End If
                                    
End If

                            
End Select
                        
Else
                            errMessage 
= "身份证日期错误"
                        
End If
                    
End If
                
End If
        
End Select
    
End Function
End Class
 

身份证规则验证 Java代码

未来可能会用,暂留(未验证) 出处:http://blog.csdn.net/suncaoyong/article/details/8647037 package com.haier.hmm...
  • fssf0079
  • fssf0079
  • 2014年02月12日 15:47
  • 4579

java身份证合法性校验

直接上代码,里面有测试类/** * 身份证前6位【ABCDEF】为行政区划数字代码(简称数字码)说明(参考《GB/T 2260-2007 中华人民共和国行政区划代码》): * 该数字码的编制原则和...
  • lib739449500
  • lib739449500
  • 2015年01月30日 13:47
  • 21043

最严格的身份证校验(Java版)

上一篇博客贴出了JavaScript版本的身份证校验,本篇博客将贴出Java版的身份证校验:...
  • wangshuxuncom
  • wangshuxuncom
  • 2014年05月20日 13:10
  • 8172

RC523读写typeA卡,身份证代码(在CubeMx STM32F407验证过)

  • 2017年12月11日 00:21
  • 33.2MB
  • 下载

《基于WinCE6.0的C#身份证验证系统实现》开题报告

  • 2018年01月10日 11:30
  • 89KB
  • 下载

《基于WinCE6.0的C#身份证验证系统实现》

  • 2018年01月10日 11:26
  • 28.4MB
  • 下载

Eclipse Java写的身份证验证程序待指正

  • 2009年06月02日 10:30
  • 883KB
  • 下载

js 实现 身份证的验证

  • 2010年03月30日 14:47
  • 1KB
  • 下载

基于API的 &quot;中国身份证计算验证&quot;

  • 2009年01月12日 15:06
  • 6KB
  • 下载

C# 一个完美的身份证验证

  • 2007年12月23日 21:23
  • 63KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:身份证验证
举报原因:
原因补充:

(最多只允许输入30个字)