RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^[0,1]?\d{1}\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3}))$
Description
This expression checks the validity of a date (US, but it is easily editable for other format's). Year's 1990-9999, Month's 1 or 01 to 12, Day's 1 or 01 to 31. Still needs to have individual months added (i.e., Feb's 28 days), and some how to check for leap year...the months issue should not be to hard, but the leap year seems like a real chore. Please let me know if you have any suggestions for leap year.
Matches
01/01/1990 | 12/12/9999 | 3/28/2001
Non-Matches
3-8-01 | 13/32/1001 | 03/32/1989
Author Rating: The rating for this expression. Scott Watermasysk
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Modification
Name: Black Cloud
Date: 4/19/2012 5:26:24 PM
Comment:
Hey I tried to modify your regex a little bit. It doesn't take 13 or 0 as month, but it still takes 0 in date field :( ^(([1][0-2])|([0]?[1-9]{1}))\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3}))$


Title: Lets through invalid months and days
Name: Jeff Adams
Date: 8/25/2009 2:09:26 PM
Comment:
matches 0/0/1990, 19/0/1990


Title: Lets through invalid months and days
Name: Jeff Adams
Date: 8/25/2009 2:08:32 PM
Comment:
matches 0/0/1990, 19/0/1990


Title: Scotts Date in German format (dd.mm.yyyy) and allowing only up to 31.12.2999
Name: Chris
Date: 4/22/2009 6:49:06 AM
Comment:
^(([0-2]?\d{1})|([3][0,1]{1}))\.[0,1]?\d{1}\.(([1]{1}[9]{1}[9]{1}\d{1})|([2]{1}\d{3}))$


Title: Regular Expression for Checking Date
Name: Syed Abdul Haq (from Pakistan)
Date: 2/14/2007 7:44:57 AM
Comment:
'This is VB .Net Function.Although Date format is different 'but you an see how it works.... 'Checks the Date Format through Regular Expressions. 'Checks for the leap year,Length of Months also 'Input Date Format : YY/MM/DD (77/07/28) Function CheckDateByRegExp(ByVal strDate As String) As Boolean Dim leapYearFormat As String = "([02468][048]|[13579][26])" Dim LeapYearFebFormat As String = "(02(0[1-9]|1[0-9]|2[0-9]))" Dim nonLeapYearFormat As String = "\d{2}" Dim NonLeapYearFebFormat As String = "([0][2]([0][1-9]|[1][0-9]|[2][0-8]))" Dim MonthsOf31DaysFormat As String = "(((0[1|3|5|7|8])|(1[02]))((0[1-9])|([12][0-9])|(3[01])))" Dim MonthsOf30DaysFormat As String = "((([0][4|6|9])|([1][1]))(([0][1-9])|([1-2][0-9])|([3][0])))" Dim nonLeapYearMonthsFormat As String = NonLeapYearFebFormat & "|" & "(" & MonthsOf30DaysFormat & "|" & MonthsOf31DaysFormat & ")" Dim leapYearMonthsFormat As String = LeapYearFebFormat & "|" & "(" & MonthsOf30DaysFormat & "|" & MonthsOf31DaysFormat & ")" Dim Dateformat As String = "^((" & leapYearFormat & "(" & leapYearMonthsFormat & "))|" & "(" & nonLeapYearFormat & "(" & nonLeapYearMonthsFormat & ")))$" If Regex.Match(strDate, Dateformat).Success Then MsgBox("True:Correct Date!!!") Return True Else MsgBox("False:Wrong Date!!!") Return False End If End Function


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials