But, can this code to test if 31/6/2001 is valid or not?
we know there are totally 30 day in June.
Thanks.
----- Original Message -----
From: "Peter Scott" <[EMAIL PROTECTED]>
To: "sachidanand haldankar" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, August 09, 2001 10:00 PM
Subject: Re: Date Validation Regex
> At 04:30 AM 8/10/01 +0530, sachidanand haldankar wrote:
> >Hi Peter,
> >
> > with the regex u sent I am still able to enter invalid date
> >
> >31/25/2001....
> >
> >my perl code is,
> >
> >$var1 = <STDIN>;
> >$var1 =~ m#^(\d\d)/(\d\d)/(\d{4})$# && $1<31 && $2<12;
> >print $&;
> >Can u please correct the error,
>
> There's nothing wrong with the code, it's your understanding of what it
> means. Observe:
>
> % cat /tmp/foo
> #!/usr/bin/perl -w
> use strict;
> my $var1 = shift;
> if ($var1 =~ m#^(\d\d)/(\d\d)/(\d{4})$# && $1<31 && $2<12) {
> print "$var1 is a valid date\n";
> }
> else {
> print "$var1 is not a valid date\n";
> }
> %$ /tmp/foo 31/25/2001
> 31/25/2001 is not a valid date
> % /tmp/foo 30/11/2001
> 30/11/2001 is a valid date
>
> You need to understand about logical operators like && (perldoc perlop)
and
> use of conditional statements like if () {} (perldoc perlsyn), both of
> which are much more fundamental and important than $&.
>
> >Thanks,
> >Anand
> >
> >
> >>From: Peter Scott <[EMAIL PROTECTED]>
> >>To: "sachidanand haldankar" <[EMAIL PROTECTED]>
> >>CC: [EMAIL PROTECTED]
> >>Subject: Re: Date Validation Regex
> >>Date: Thu, 09 Aug 2001 15:30:28 -0700
> >>
> >>At 03:59 AM 8/10/01 +0530, you wrote:
> >>>Hi Peter,
> >>>
> >>> I have made the changes already. Thanks a lot but its hurtning. Just
> >>>started with Regxes. I assure u, Here after u will get some thing
> >>>apprciabely ok. Can u suggest better site for regexes
> >>
> >>Get Jeff Friedl's book 'Mastering Regular Expressions" from
> >>O'Reilly. Also, "perldoc perlretut" gives you a tutorial if you have
Perl
> >>5.6.1.
> >>
> >>>Thanks,
> >>>Anand
> >>>
> >>>
> >>>>From: Peter Scott <[EMAIL PROTECTED]>
> >>>>To: <[EMAIL PROTECTED]>,<[EMAIL PROTECTED]>
> >>>>Subject: Re: Date Validation Regex
> >>>>Date: Thu, 09 Aug 2001 15:22:21 -0700
> >>>>
> >>>>At 03:16 PM 8/9/01 -0700, I wrote:
> >>>>>At 05:43 PM 8/9/01 -0500, [EMAIL PROTECTED] wrote:
> >>>>>>Hi ,
> >>>>>>
> >>>>>> Can anybody help me to write regex for date validation. The
> >>>>>>validation criterion will be as below,
> >>>>>>
> >>>>>>with date in format dd/mm/yyyy &
> >>>>>>
> >>>>>>dd - should be less than 31
> >>>>>
> >>>>>Really? You're starting from 0?
> >>>>>
> >>>>>>mm - should be less than 12
> >>>>>
> >>>>>Ditto.
> >>>>>
> >>>>>>yyyy - no validation
> >>>>>
> >>>>>Not everything should be done with a single regex, even though
anything
> >>>>>can be. Here:
> >>>>>
> >>>>> $date =~ m#^(\d\d)/(\d\d)/(\d{4})$/ && $1 < 31 && $2 < 12
> >>>>
> >>>>Rats, hit Send too soon. The delimiter is #, not /:
> >>>>
> >>>> $date =~ m#^(\d\d)/(\d\d)/(\d{4})$# && $1 < 31 && $2 < 12;
> >>>> # Now use date in ($1, $2, $3)
> >>>>--
> >>>>Peter Scott
> >>>>Pacific Systems Design Technologies
> >>>>http://www.perldebugged.com
> >>>
> >>>
> >>>_________________________________________________________________
> >>>Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp
> >>
> >>--
> >>Peter Scott
> >>Pacific Systems Design Technologies
> >>http://www.perldebugged.com
> >
> >
> >_________________________________________________________________
> >Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp
> >
>
> --
> Peter Scott
> Pacific Systems Design Technologies
> http://www.perldebugged.com
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]