Title |
Test
Find
Pattern Title
|
Expression |
^(((((0[1-9])|(1\d)|(2[0-8]))-((0[1-9])|(1[0-2])))|((31-((0[13578])|(1[02])))|((29|30)-((0[1,3-9])|(1[0-2])))))-((20[0-9][0-9]))|(29-02-20(([02468][048])|([13579][26]))))$ |
Description |
This expression validates a date field in the European DD-MM-YYYY format. Days are validate for the given month and year. |
Matches |
05-01-2002 | 29-02-2004 | 31-12-2002 |
Non-Matches |
1-1-02 | 29-02-2002 | 31-11-2002 |
Author |
Rating:
Jörg Maag
|
Source |
|
Your Rating |
|
Title: perfect!
Name: Mona
Date: 10/21/2006 2:23:00 PM
Comment:
Wooohoooo nice job!!! I was looking exactly for this! (The one corrected by Isha
Thank You
Title: For Isha: good work but...
Name: Roberto
Date: 3/6/2005 7:14:06 AM
Comment:
Compliments to Isha for its work. I used it in Javascript, replacing [/ -] with \/ (now match only dates with / as separator), because [/ -] doesn't work in Javascript (and I needed only / not -).
^(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/(([0-9][0-9][0-9][0-9]))|(29\/02\/[0-9][0-9](([02468][048])|([13579][26]))))$/
Title: Simply the simplest
Name: Isha
Date: 8/11/2004 1:12:45 AM
Comment:
It is realy a good piece for date validatin. It's such a simple logic that you can understand and modify it according to your need, very easily.
to make it work with any year 0000-9999 and with /,space or - simple changes are required like
- to [/ -]
20[0-9][0-9] to [0-9][0-9][0-9][0-9]
^(((((0[1-9])|(1\d)|(2[0-8]))[/ -]((0[1-9])|(1[0-2])))|((31[/ -]((0[13578])|(1[02])))|((29|30)[/ -]((0[1,3-9])|(1[0-2])))))[/ -](([0-9][0-9][0-9][0-9]))|(29[/ -]02[/ -][0-9][0-9](([02468][048])|([13579][26]))))$
Thank you
Title: Doesnt work brilliantly with PHP
Name: Dave
Date: 7/1/2004 12:03:51 PM
Comment:
Dont know why but it doesnt work with PHP when trying the date 10-07-2004, i have changed the \d part of the expression to [0-9] and that seems to have fixed it, maybe my version of php doesnt support some of the special features. P.S. You can get this to work with all years, just have a fiddle with the ((20[0-9][0-9])) part of the expression. Good work all in all! :o)
Title: Doesn't match below year 2000
Name: Will Earp
Date: 6/18/2003 7:52:11 AM
Comment:
Pretty good but doesn't match any dates with a year below 2000