At 08:17 PM 8/10/01 +0530, sachidanand haldankar wrote:
>Hi Peter,
>
>    Thanks for ur quick response. Its seems to be working fine. Thanks a 
> lot for that. What I am trying to do is to write a Regex for date 
> validation in a xml file used in CMS environment(using InterWoven). There 
> is a attribute in a text element called "validation-regex" where I can 
> write Regex for data i/p validation. But in this case, I am not able to 
> write conditional regexes.

See, that's a way different question.  That's not even about Perl regular 
expressions.

Okay, maybe somthing like this (just the regex, and assuming leading zeroes 
since you said the format was dd/mm/yyyy).  Mind you, I'm just guessing as 
to whether this format will be acceptable to the Interwoven regex engine; 
you need someone who knows that product, not a Perl person.  and as others 
have pointed out, it still doesn't stop someone from entering a date of 
31/02/2001.

    (0[1-9]|[12][0-9]|3[01])(0[1-9]|1[012])[12][09][0-9][0-9]

>Thanks,
>Anand
>
>
>
>>From: Peter Scott <[EMAIL PROTECTED]>
>>To: "sachidanand haldankar" <[EMAIL PROTECTED]>,[EMAIL PROTECTED]
>>Subject: Re: Date Validation Regex
>>Date: Thu, 09 Aug 2001 22:00:36 -0700
>>
>>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
>
>
>_________________________________________________________________
>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]

Reply via email to