I'm looking for a simple regex that verifies a date in the format DD/MM/YYYY.
^([0123][0-9])\/([01][0-2])\/[12][09][0-9][0-9] seems to be the right way... Is it possible to validate that the 00 < DAY <= 31 and 00 < MONTH <=12?
-i put in a trailing dollar sign to mark the end of the string. It does just what you asked for and no more (ie. this string will not match for dates in year 3000 and beyond.)
You may want to replace "\/" with a dot "." to allow for other separators, ie. "-" or "."
/claus
Added: included this link, there's a very advanced regexp on top that also validates the dates (leap years and month leghts) from 1/1/1600 - 12/31/9999:
[regexlib.com...]
Note: Remember to replace the broken pipe "¦" with one you enter from your keyboard - this board replaces the real pipes with a character that just looks like them but is not the same (it should not be broken)
[edited by: claus at 10:12 am (utc) on Aug. 11, 2003]
Added:
Validate regexps here: [regexlib.com...]
/claus
- what? It works perfectly fine for me, i'm really sad to hear this... otherwise i wouldn't have posted it in the first place... are you sure:
(1) you remembered to replace all three broken pipes "¦" with a real one entered from your keyboard?
(2) that you have also removed any preceding or trailing spaces?
(3) that you are using the format "DD/MM/YYYY"?
(4) that you are using dates in the range you specified?
(5) that these dates are between 01/01/1000 and 31/12/2999?
(6) that you write no other thinghs in the "Text To Check:" field than a date following (3), (4), and (5) - not even spaces.
I am sure that one of these six is the problem. I do not know Interwowen Teamsite, but i am alomost 100% sure that it does not interfere with the processes taking place at regexplib.com's servers, so that's probably not the reason. Try very carefully to examine each of these six steps, i'm sure it works, and i just re-tested it without problems.
>> only regex that seems to work in this environ. is ^[0-3][0-9]\/[0-1][0-9]
Not just annoying, but really annoying, because that means that you will accept dates like 39/19/2003 ... we must get this solved for you somehow...
/claus