- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
Matches ANSI SQL date format YYYY-mm-dd hh:mi:ss am/pm. You can use / - or space for date delimiters, so 2004-12-31 works just as well as 2004/12/31. Checks leap year from 1901 to 2099.
2004-2-29 | 2004-02-29 10:29:39 pm | 2004/12/31
2003-2-29 | 2003-13-02 | 2003-2-2 10:72:30 am
Author Rating: The rating for this expression. Sung Lee
Your Rating
Bad Good

Enter New 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: Read the description
Name: Sung Lee
Date: 7/27/2005 4:04:55 PM
The description says it only works up to 2099.

Title: Does not validate 100% leap years
Name: Tester
Date: 7/27/2005 4:19:30 AM
date like 2100-2-29 should not be validated :) Review your leap years definition. Regards

Title: Very Good!
Name: Chas Chen
Date: 2/17/2005 12:10:56 AM
That's good and it works in jsp! Thank u !

Title: Re: how to implement?
Name: Michael Ash
Date: 9/27/2004 9:48:17 AM
You are using a mm-dd-yyyy date regex. If you are testing with a yyyy-mm-dd formatted date that's not going to match.

Title: Problem in your code
Name: Sung Lee
Date: 9/26/2004 11:05:43 PM
Sorry, the code got truncated. I suggest you re-copy and paste the regular expression from this website into your code. You're using the wrong regular expression it looks like. Also I suggest you strongly type your variables.

Title: Problem in your code
Name: Sung Lee
Date: 9/26/2004 11:03:08 PM
I think your code isn't working because you are not using the correct regular expression. This code works: <code> Dim regexDateFormat As String = "" & _ "^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578]" & _ ")|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[4" & _ "69])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\" & _ "s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([1" & _ "3579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((" & _ "0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((" & _ "0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9]" & _ ")|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(" & _ "\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$" Dim startDate As String = txtDateTime.Text Dim ValidDate As Boolean = False ValidDate = System.Text.Regular

Title: how to implement?
Name: Marshall
Date: 9/24/2004 5:35:25 PM
What am I doing wrong here? without the NOT, every input is accepted; with the not, everything is changed? <code> sub VerifyDates(Sender As Object, E As EventArgs) Dim regexDateFormat= "" & _ "^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0" & _ "?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?" & _ "\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|" & _ "[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)" & _ ")))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8]" & _ ")\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[0" & _ "12])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2}" & _ ")?$" Dim startDate=txtStartDate.text Dim ValidDate = 0 ValidDate = Regex.IsMatch(startDate,regexDateFormat) if((startDate="yyyy-mm-dd") OR NOT (ValidDate)) txtStartDate.text() = DateTime.Today.ToString("yyyy-MM-dd") end if end sub </code> Thanks!

Title: nOT WORK
Name: B3B4
Date: 6/30/2004 3:14:32 AM

Title: You need to escape the \'s
Name: A. C. Guy
Date: 5/18/2004 5:55:09 PM
That's why it works in VB and not in C#. Same deal if you're using C/C++.

Title: Fixed a bug
Name: Sung Lee
Date: 11/3/2003 1:36:18 PM
I fixed a bug where it would accept xxxx/11/31 as a valid date. I'm not sure why your .NET code isn't working. I tried it in VB.NET and it worked fine. You might want to verify that args[0] is the value you are expecting it to be.

Title: Does Not Work in .NET?
Name: Anony Mouse
Date: 11/1/2003 11:17:43 AM
using System; using System.Text.RegularExpressions; class DtTest { [STAThread] static void Main(string[] args) { string ansiDateRegex = @"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[0-2]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$ "; if ( Regex.Match( args[0] , ansiDateRegex ).Success == false ) { Console.WriteLine( "false" ); } else { Console.Write( "true" ); } } } Above code returns false when tried with these samples: 2004-2-29|||2004-02-29 10:29:39 pm|||2004/12/31

Copyright © 2001-2018, | ASP.NET Tutorials