Mark,
In article <[EMAIL PROTECTED]>, Mark Byerley wrote:
>I need some error checking (or rather field validation) within my script
>itself to ensure a date field coming across on a form is in the format of
>dd-mm-yyyy. I would rather not have to strip the field down to check the
>individual numbers and then put them back together again. Is there any
>"simple" type of error checking I can use in this instance?
I think testing against a regexp would give you what you want. Here's what
I whipped up for the job:
----begin sample code
#!/usr/bin/perl -w
$compare1 = "04-12-2001"; # Passes test
$compare2 = "04/12/2001"; # Fails test
$compare3 = "4-12-01"; # Another failure
foreach $var ($compare1, $compare2, $compare3) {
if ( $var !~ m/\d{2}-\d{2}-\d{4}/ ) { # If format wasn't ##-##-####,
print "$var: Failed formatting test\n"; # print error message.
} else { # Otherwise, we print
print "$var: Passed formatting test\n"; # success message
}
}
----end sample code
Hope that does it for you!
John
--
John Fox <[EMAIL PROTECTED]>
System Administrator, InfoStructure, Ashland OR USA
---------------------------------------------------------
"What is loved endures. And Babylon 5 ... Babylon 5 endures."
--Delenn, "Rising Stars", Babylon 5
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]