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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Date
Expression
^(\d{4}(?:(?:(?:\-)?(?:00[1-9]|0[1-9][0-9]|[1-2][0-9][0-9]|3[0-5][0-9]|36[0-6]))?|(?:(?:\-)?(?:1[0-2]|0[1-9]))?|(?:(?:\-)?(?:1[0-2]|0[1-9])(?:\-)?(?:0[1-9]|[12][0-9]|3[01]))?|(?:(?:\-)?W(?:0[1-9]|[1-4][0-9]5[0-3]))?|(?:(?:\-)?W(?:0[1-9]|[1-4][0-9]5[0-3])(?:\-)?[1-7])?)?)$
Description
This is a regular expression to check for a properly formatted date according to the international date and time notation ISO 8601. Remember, this is just for the date. See ISO 8601 specification for more information.
Matches
ISO 8601 date format
Non-Matches
non-ISO date format
Author Rating: The rating for this expression. tedcambron
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: Works Perfectly
Name: Ted Cambron
Date: 9/24/2014 8:14:36 PM
Comment:
I just tested this beauty again and it works perfectly as intended.


Title: Leap years and short-long months
Name: Robajz
Date: 8/28/2011 10:39:54 AM
Comment:
Hi, Thanks for the pattern. I have expanded it to support leap years and short-long months here: http://regexlib.com/REDetails.aspx?regexp_id=3344 Regards, Rob


Title: Hmm...
Name: Ted Cambron
Date: 11/16/2008 10:55:14 AM
Comment:
I don't understand what's going on with this. It works using the regex coach but not on the tester here. I wonder what it could be.


Title: Hmm...
Name: Ted Cambron
Date: 11/16/2008 10:55:04 AM
Comment:
I don't understand what's going on with this. It works using the regex coach but not on the tester here. I wonder what it could be.


Title: Hmm...
Name: Ted Cambron
Date: 11/16/2008 10:53:38 AM
Comment:
I don't understand what's going on with this. It works using the regex coach but not on the tester here. I wonder what it could be.


Title: Hmm...
Name: Ted Cambron
Date: 11/16/2008 10:49:57 AM
Comment:
I don't understand what's going on with this. It works using the regex coach but not on the tester here. I wonder what it could be.


Title: Does not work :(
Name: Mike
Date: 10/6/2008 4:06:46 PM
Comment:
Try a few examples from this note: http://www.w3.org/TR/NOTE-datetime Unfortunately most of them are rejected by this REGEX


Title: Doesn't work
Name: Michael Newman
Date: 5/23/2008 3:03:37 PM
Comment:
This doesn't match iso 8601 format


Title: Updated
Name: Ted Cambron
Date: 2/12/2008 10:41:16 PM
Comment:
I updated it so that the day of year is 001 - 366, the week number is 01 - 53, and day of week number is 1 - 7. I also updated the month and day part to restrict it to more realistic numbers.


Title: Can be improved
Name: Ted Cambron
Date: 2/9/2008 8:55:58 PM
Comment:
I just noticed that even though the formatting is to specification it will allow unrealistic dates. Can be improved.


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