On Tue, Nov 15, 2011 at 4:01 PM, Yitzchak Scott-Thoennes <sthoe...@gmail.com
> wrote:

> This is something people often ask for.  The stock answer is that
> regexes aren't the correct solution, but really it's not so hard.
>
> This validates Gregorian MM/DD/CCYY dates, for example:
>
> qr#^
>    (?: 0[1-9] | 1[012] )
>    /
>    (?:
>        0[1-9] | 1[0-9] | 2[0-8]
>        | (?<! 0[2469]/ | 11/ ) 31
>        | (?<! 02/ ) 30
>        | (?<! 02/
>             (?= ...
>                 (?:
>                     .. (?: [02468][1235679] | [13579][01345789] )
>                     | (?: [02468][1235679] | [13579][01345789] ) 00
>                 )
>             )
>        ) 29
>    )
>    /
>    [0-9]{4}
>    \z
> #x
>

No. Just, no.
Read this:
http://stackoverflow.com/questions/4077896/perl-or-python-convert-date-from-dd-mm-yyyy-to-yyyy-mm-dd/4078817#4078817
Then forget about using regexen and find a module to do it for you.
Regexp::Common::time is pretty nice, albeit slow if you are doing millions
of validations.

(But in the spirit of this list, sure, that's cool. Would be cooler if you
could abstract it using (?(DEFINE)) :)

Reply via email to