A regex that checks values like that is going to be far too complex to maintain. You're better off using a function that checks for valid dates. The timelocal function from Time::Local, converts a list of values (like those returned from localtime) into a epoch seconds value and it dies if passed an invalid date. You can use eval to catch and report on those errors.
#!/usr/bin/perl use strict; use warnings; use Time::Local; while (<DATA>) { chomp; my ($y, $m, $d) = split /-/; eval { timelocal 0, 0, 0, $d, $m-1, $y-1900 }; if ($@) { print "$_ is not a valid date\n"; } else { print "$_ is a valid date\n"; } } __DATA__ 2006-10-30 2006-10-32 2006-02-29 2004-02-29
It's simple enough to wrap that up into a is_valid_date function.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: ultimate date check regexp
by davorg
in thread ultimate date check regexp
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |