Re: checking user input of MM-DD-YYYY
| From: | Richard Lynch | Date: | Tue, 15 Jan 2008 15:36:20 +0000 |
| Subject: | Re: checking user input of MM-DD-YYYY | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-267293@lists.php.net to get a copy of this message | ||
On Tue, January 15, 2008 8:27 am, Adam Williams wrote:
> I'm having users enter dates in MM-DD-YYYY format. is there a way to
> check if what they have entered is invalid (like if they enter
> 1-15-2008
> instead of 01-15-2008) ?
Making the user type the 0 is just plain rude. :-)
You could use a javascript popup calendar to make MOST users have it
the way you want.
And something like this can validate what you think you want:
if (preg_match('/^([0-9]{2}-[0-9]{2}-[0-9]{4}$/', $date, $date_parts)){
list($month, $day, $year) = $date_parts[1];
$unixdate = mktime(1, 0, 0, $month, $day, $year);
$crosscheck = date('M-d-Y', $unixdate); //Is M for zero-padded month?
if ($crosscheck != $date_parts[0]) error();
}
else error();
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?