Gsulinux wrote at Sat, 27 Jul 2002 13:32:27 +0200:
> I wanna check the information typed in the form field whether if it is in date
>format or not .
> Like : check it if it is in format day/mount/year , in format like ab/cd/ef or
>ab/cd/efgh "ab"
> must be valid like between 1-31
> "cd" must be valid between 1-12 or must be a string that exist in an array that i
>define, for
> exemple A[12] "ef" must be valid like between 00-99 or "efgh" between 1900-2010
>
> In second part i wanna get the month in a variable, i mean "cd" to a variable , "cd"
>can be either
> a numeric value or a string
There's no real difference between a numeric value and a string in Perl.
There's only a difference in the context using the values.
E.g.
03 == 3 # but
"03" ne "3"
>
> Can u help me writing that regular exp.?!?
What have you tried so far ?
In the most cases,
it's enough to say
my ($day, $month, $year) = m:(\d\d)/(\d\d)/(\d\d):; # to match ab/cd/ef
my ($day, $month, $year) = m:(\d\d)/(\d\d)/(\d{4}):; # to match ab/cd/efgh
and ignoring the constraints for a day, month, year.
of course,
you can also build complicate regexes like
my $day_re = qr/\d | [012]\d | 3[01]/x;
my $month_re = qr/\d | 0\d | 1[012]/x;
my $year_re = qr/19\d\d | 200\d | 2010/x;
and then write
my ($day, $month, $year) = m:($day_re)/($month_re)/($year_re):;
But note that it doesn't mean to be a valid date,
as 30/02/1997 isn't valid at least.
Best is, as already mentioned of Fliptop to use one of
the many Date::* modules
Best Wishes,
Janek
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]