RE: [PHP] Ereg question
| From: | John W. Holmes | Date: | Sun, 30 Mar 2003 19:28:20 +0000 |
| Subject: | RE: [PHP] Ereg question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-141649@lists.php.net to get a copy of this message | ||
> 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/