求一个判断时间输入是否合理的正则表达式
时间形式:2009-10-1 2009-10-01 2009-2-1 
另外年的区间范围2000到2099就行

解决方案 »

  1.   

       var regex = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
    能过2009-9-25 2009-09-02 2009-9-2 2009-09-25
      

  2.   

    Public Function checkDate(ByVal strDate As String) As Boolean        Dim iDay As Integer = 0        If strDate.Length <> 8 Then
                Return False
            End If        If CInt(strDate.Substring(0, 4)) < 1900 Or Int(strDate.Substring(0, 4)) > 9999 Then
                Return False
            End If        If CInt(strDate.Substring(4, 2)) < 1 Or Int(strDate.Substring(4, 2)) > 12 Then
                Return False
            End If        iDay = fnComputerDay(CInt(strDate.Substring(0, 4)), CInt(strDate.Substring(4, 2)))        If CInt(strDate.Substring(6, 2)) > iDay Or CInt(strDate.Substring(6, 2)) < 1 Then
                Return False
            End If        Return True
        End Function
        Public Function fnComputerDay(ByVal intYear As Integer, ByVal intMonth As Integer) As Integer        Dim intDay As Integer        intDay = Date.DaysInMonth(intYear, intMonth)        Return intDay    End Function
      

  3.   

    http://topic.csdn.net/t/20060309/11/4602859.html
      

  4.   

    我们得到最终的验证日期格式为YYYY-MM-DD 的正则表达式为:(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) 
    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/LCL_data/archive/2010/01/20/5218509.aspx