Re: Ereg question
| From: | Beauford | Date: | Sun, 30 Mar 2003 19:51:12 +0000 |
| Subject: | Re: Ereg question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-141650@lists.php.net to get a copy of this message | ||
$parts has been removed as I found I didn't need it there, but the problem
still exists. This part of code however may be causing the problem, although
I thought trim only stripped white space.....?. $formsave['dob'] is a
session variable. I have also found now that leading 0's are also being
stripped.
foreach($HTTP_POST_VARS as $varname => $value)
$formsave[$varname] = trim($value, 50);
If it's not there then the whole script fails.
B.
----- Original Message -----
From: "John W. Holmes" <holmes072000@charter.net>
To: "'Beauford'" <beauford.2002@rogers.com>; "'PHP
General'"
<php-general@lists.php.net>
Sent: Sunday, March 30, 2003 2:28 PM
Subject: RE: [PHP] Ereg question
> > I am using ereg to validate the format of a date entry (mm/dd/yy), but
> if
> > the year ends in a 0, it is being stripped and as such produces an
> error.
> > So
> > 1990 would be 199. The dob is being inputted by a form....
> >
> > Here is my code:
> >
> > if (!ereg("^([0-9]{2})/([0-9]{2})/([0-9]{4})$", $formsave["dob"],
> $parts))
> > {
> > $error["dob"] = "*"; $message["dob"] = "Invalid date
> > format!";
> > $dob = " \"$parts[3]-$parts[2]-$parts[1]\"";
> > }
>
> So is $formsave['dob'] being changed before you get to this code,
> causing the check to fail? What else are you doing with
> $formsave['dob']? Nothing here is going to cause it to drop a zero from
> the end.
>
> Your code doesn't make much sense, though. If the ereg() fails, $parts
> is not going to have any value, so why are you referencing $part[1],
> $part[2], etc... ?
>
> ---John W. Holmes...
>
> PHP Architect - A monthly magazine for PHP Professionals. Get your copy
> today. http://www.phparch.com/
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>