sub isvaliddate { my $input = shift; if ($input =~ m/^((?:19|20)\d\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/) { # At this point, $1 holds the year, $2 the month and $3 the day of the dat if (($3 == 31) and ($2 == 4 or $2 == 6 or $2 == 9 or $2 == 11)) { return 0; # 31st of a month with 30 days } elsif ($3 >= 30 and $2 == 2) { return 0; # February 30th or 31st } elsif ($2 == 2 and $3 == 29 and not ($1 % 4 == 0 and ($1 % 100 > 0 or $1 return 0; # February 29th outside a leap year } else { return timelocal(0,0,0,$3,$2-1,$1); } } else { return 0; # Not a date } }