English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi,can anyone help me. i need to verify that a users data entered is correct using Perl, i want to check that the date they enter is in the correct format, eg dd/mm/yy.
thx

2006-11-14 23:40:38 · 3 answers · asked by karljj1 4 in Computers & Internet Programming & Design

It has to be done using perl

2006-11-14 23:53:48 · update #1

3 answers

Something along the lines of:
my ($day,$month,$year) = split (/\//, $date);
die "Bad date" unless ($day < 32 && $month < 13 & $year);

or, to be more strict:

my ($day,$month,$year) = ($1,$2,$3) if $date =~ m'(\d\d)/(\d\d)/(\d\d)';
die "Bad date" unless ($day < 32 && $month < 13 & $year);

Or, if you are on a normal (non-windoze) os, just do
die "Bad date" unless `date -d "$date" +%d/%m/%y 2>/dev/null`;

2006-11-14 23:49:09 · answer #1 · answered by n0body 4 · 0 0

$date = '05/11/87';
$date =~ /^(\d\d)\/(\d\d)\/(\d\d)$/;
($month, $day, $year) = ($1, $2, $3);


if ($month)
{

if ( ($month <= 12 && $month >= 1) && ($day <= 31 && $day >= 1) ) { print "Correct input"; } #

else { print "Incorrect Input"; }

}
else { print "Wrong format"; }


----

This will make sure that mm/dd/yy is entered exactly..

2006-11-17 13:27:02 · answer #2 · answered by Kejento 2 · 0 0

Where is the data being entered? You could check the data format using Javascript which is much easier...

2006-11-15 07:52:41 · answer #3 · answered by Tamayi M 2 · 0 1

fedest.com, questions and answers