Date checking syntax 
Author Message
 Date checking syntax

I must be missing something really simple - this doesn't look like it
should be that hard.

I would like to confirm that an argument supplied to a script is in the
format ##/##/## where the # can be either one or two digits.

if ($date !~ /\d{1,2}\/\d{1,2}\/\d{1,2}/)
{       print "ERROR: $date\n";       }

should do it, I would think.  It catches it if I try to throw characters
in there, but doesn't catch the 3 digit months or days.  

Can someone tell me what I f%^&U up?

thanks.

Doug

--
--------
Douglas K. O'Leary
Senior UNIX Admin
resume:   http://www.*-*-*.com/ ~dkoleary/resume.html



Wed, 11 Aug 2004 21:16:41 GMT  
 Date checking syntax

Quote:

> I must be missing something really simple - this doesn't look like it
> should be that hard.

Ohh, I get it - and yes, it was really simple.

My test case was 123/12/12 which matched because there were two digits
in the first field.  I had to put an anchor on the first field:

if ($date !~ /^\d{1,2}\/\d{1,2}\/\d{1,2}/)

Then it worked the way I was looking for.  Amazing, you post a message
and the answer comes to you - you don't even have to wait for the
replies!

Doug

--
--------
Douglas K. O'Leary
Senior UNIX Admin
resume:  http://home.attbi.com/~dkoleary/resume.html



Wed, 11 Aug 2004 21:25:03 GMT  
 Date checking syntax

Quote:



> > I must be missing something really simple - this doesn't look like it
> > should be that hard.

> Ohh, I get it - and yes, it was really simple.

> My test case was 123/12/12 which matched because there were two digits
> in the first field.  I had to put an anchor on the first field:

> if ($date !~ /^\d{1,2}\/\d{1,2}\/\d{1,2}/)

> Then it worked the way I was looking for.  Amazing, you post a message
> and the answer comes to you - you don't even have to wait for the
> replies!

> Doug

you might wanna anchor the end too...and use alternate delimiters for
readability:

if ($date !~ m|^\d{1,2}/\d{1,2}/\d{1,2}$|)

hth-
--
Michael Budash
Michael Budash Consulting



Wed, 11 Aug 2004 22:25:58 GMT  
 Date checking syntax

Quote:

> you might wanna anchor the end too...and use alternate delimiters for
> readability:

> if ($date !~ m|^\d{1,2}/\d{1,2}/\d{1,2}$|)

Yea, I'd already figured the end anchor as well.  When I first started
this thing, I was using a bang for the delimiter.  That went away while I
was trying to troubleshoot the damned thing.  Now that it's working, I'll
just leave it.

Thanks for the response.

Doug

--
--------
Douglas K. O'Leary
Senior UNIX Admin
resume:  http://home.attbi.com/~dkoleary/resume.html



Thu, 12 Aug 2004 20:49:18 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Can someone check my syntax here?

2. Fast HTML syntax checking package for CGI scripts

3. syntax check on domain-names (HowTo)?

4. Check Syntax

5. Syntax checking without "perl -c"?

6. syntax check without execution

7. Syntax checking a Perl script

8. Regular Expression Syntax Checking

9. Need Help Checking IP Address Syntax w/ PERL?

10. please check my CGI.pm/Perl Syntax

11. html syntax check

12. Bad syntax check with perl -c

 

 
Powered by phpBB® Forum Software