in reply to Script to validate date fails
Adding to what runrig said, Date::Calc has the fastest date validation.
use strict; use warnings; use Date::Calc "check_date"; print "Enter the date in yyyy-mm-dd format : "; # More "native" format +. while ( my $date = <STDIN> ) { last if $date =~ /^$/; my @date = $date =~ /(\d+)/g; # Allows any separator and mushy inp +ut. if ( eval { check_date( @date ) } ) { print "You have entered valid data\n"; } else { print "You have entered invalid data\n"; } print "Enter the date in yyyy-mm-dd format : "; } __END__ Enter the date in yyyy-mm-dd format : ohai You have entered invalid data Enter the date in yyyy-mm-dd format : 2012-2-29 You have entered valid data Enter the date in yyyy-mm-dd format : 2011-2-29 You have entered invalid data Enter the date in yyyy-mm-dd format :
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Script to validate date fails
by Not_a_Number (Prior) on Feb 16, 2012 at 17:15 UTC |