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-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00|[048])))$
Description
This regexp has been posted specialy for "Mike O Shea" as he requested a mono digit year validation. matches DD/MM/Y or DD/MM/YYYY or D/M/Y or DD/M/YYYY Leap years treated. (Italian style with tomato) Years 0-9 equal years 2000 to 2009 for leap years
Matches
1/1/2005 | 29/02/12 | 29/02/2400
Non-Matches
29/2/2005 | 29/02/13 | 29/02/2200
Author Rating: The rating for this expression. Dany Lauener
Source Dany Lauener
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: Mr
Name: Vinoth
Date: 1/28/2009 1:26:25 AM
Comment:
mail me to 4nvinoth@gmail.com would be more helpfull. thanks in advance.


Title: Mr
Name: Vinoth
Date: 1/28/2009 1:25:06 AM
Comment:
Can you help me? I need the same regex but it should allow only 4 digit year instead of 2 digits or 1 digit. match cases: 1/1/2009, 01/01/2009, 01/1/2009, 1/01/2009 non-matching cases: 1/1/1, 1/1/01


Title: Mr
Name: Vinoth
Date: 1/28/2009 1:22:04 AM
Comment:
Can you help me? I need the same regex but it should allow only 4 digit year instead of 2 digits.


Title: Mr
Name: Vinoth
Date: 1/28/2009 1:21:23 AM
Comment:
Can you help me? I need the same regex but it should allow only 4 digit year instead of 2 digits.


Title: Avoid using regular expressions for dates
Name: Mike
Date: 4/14/2004 9:10:46 AM
Comment:
I just found out that in ASP.NET you can use the code below to validate date type and range and avoid using expressions altogether. As far as I'm aware, both validators take the regional format into account for dates. <asp:TextBox id="txtDate1" Columns="10" runat="server" /> <asp:CompareValidator id="cvDate" runat="Server" Operator="DataTypeCheck" Type="Date" ErrorMessage="Enter a valid date" ControlToValidate="txtDate1" /><br> <asp:RangeValidator id="rvDate" runat="Server" Type="Date" MinimumValue="1/1/2003" MaximumValue="31/3/2003" ErrorMessage="Enter a date between 1/1/2003 and 31/3/2003" ControlToValidate="txtDate1" /> This wouldn't have worked for me as I needed 1 digit years but may be useful to others who are not aware of this functionality.


Title: Perfect!!!
Name: Mike
Date: 4/14/2004 3:56:22 AM
Comment:
This is exactly what I was looking for and the expression now works perfectly for 1 digit years as well as all other variation. Thanks for taking the time to solve this and for your very prompt response.


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