in reply to Simple Date Validation
Looking at the Time::Local documentation, I see the following:
The timelocal() and timegm() functions perform range checking on the input $sec, $min, $hour, $mday, and $mon values by default.
So, I would just exploit that and hand the parts of the date to, say, timelocal, and see if it accepts these values as valid or not:
my ($sec,$min,$hour) = qw( 0 0 12 ); my ($mday, $mon, $year) = qw(11 5 2007); $mon--; # because that's how unix/C treat the month value eval { my $dummy = timelocal($sec,$min,$hour,$mday,$mon,$year); }; if (my $err = $@) { print "This is an invalid date."; } else { print "Yay"; };
Splitting up $userdate into the parts making up the day, month and year is left as an exercise to the reader.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple Date Validation
by Trihedralguy (Pilgrim) on May 11, 2007 at 15:38 UTC | |
by shmem (Chancellor) on May 11, 2007 at 16:11 UTC | |
by naikonta (Curate) on May 11, 2007 at 15:48 UTC | |
|
Re^2: Simple Date Validation
by ad1mt (Initiate) on Sep 25, 2008 at 15:15 UTC | |
by Corion (Patriarch) on Sep 25, 2008 at 15:19 UTC |