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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^((((([13578])|(1[0-2]))[\-\/\s]?(([1-9])|([1-2][0-9])|(3[01])))|((([469])|(11))[\-\/\s]?(([1-9])|([1-2][0-9])|(30)))|(2[\-\/\s]?(([1-9])|([1-2][0-9]))))[\-\/\s]?\d{4})(\s((([1-9])|(1[02]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$
Description
This expression can be used validate a datetime column from SQL Server. Big parts of it where taken from other samples on RegexLib. Please feel free to take it apart and improve it.
Matches
3/3/2003 | 3/3/2002 3:33 pm | 3/3/2003 3:33:33 am
Non-Matches
13/1/2002 | 3/3/2002 3:33 | 31/3/2002
Author Rating: Not yet rated. Scott Watermasysk Watermasysk
Source RegexLib
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: Roushan
Date: 11/16/2017 6:53:23 AM
Comment:
30/06/2017 10:10:03 PM giving wrong.


Title: Matches numbers
Name: Chris
Date: 3/11/2014 10:31:34 AM
Comment:
This also matches any 6- 8 digit number which is undesirable


Title: Matches numbers
Name: Chris
Date: 3/11/2014 10:31:00 AM
Comment:
This also matches any 6- 8 digit number which is undesirable


Title: does not match two digit years as advertised
Name: bill
Date: 11/13/2007 9:00:36 AM
Comment:
does not match two digit years as advertised


Title: DateTime format = 3/3/2003 3:33:33 am
Name: David Alexander
Date: 2/14/2005 10:55:14 AM
Comment:
Anyway this could be modified to only except matche with this format: 3/3/2003 3:33:33 am Any help would be appreciated! David


Title: This fixes the limitations with the regex
Name: Charley
Date: 9/2/2003 2:45:50 PM
Comment:
This one accepts leading zero months, days and hours. Also the bug with the 11th hour not being a match is fixed. ^(((((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]))))[\-\/\s]?\d{4})(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$


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