身份证验证

原创 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
 

相关文章推荐

17位身份证验证

  • 2017年06月21日 22:00
  • 2KB
  • 下载

身份证号升位验证真伪小软件

  • 2012年11月15日 11:26
  • 46KB
  • 下载

java代码验证身份证号码经典版

package com.haier.hmms.util; import java.text.SimpleDateFormat; import java.util.Date; /**  * 验证...

C#验证身份证是否符合规则

  • 2012年10月24日 11:29
  • 18KB
  • 下载

js身份证号码验证

  • 2012年02月15日 13:33
  • 6KB
  • 下载

java验证身份证号码及编码规则和提取相应信息

java验证身份证号码及编码规则和提取相应信息 转自 http://www.cnblogs.com/tenking/archive/2009/12/07/2075290.html ...

身份证的相关验证

  • 2012年05月31日 15:02
  • 1KB
  • 下载

C#377-身份证验证器源代码

  • 2017年07月22日 22:22
  • 134KB
  • 下载

js正则表达式——验证邮箱格式、邮编、身份证号码、是否为空、下拉框选项、密码、手机号码、电话号码

JS正则表达式 1)验证密码    function verifyPassword(str){       var reg=/^[A-Za-z0-9]+$/;       if( reg.test(s...

Java详细验证身份证实例代码

  • 2017年07月27日 14:13
  • 8KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:身份证验证
举报原因:
原因补充:

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