Re: checking user input of MM-DD-YYYY
| From: | Jim Lucas | Date: | Tue, 15 Jan 2008 18:16:11 +0000 |
| Subject: | Re: checking user input of MM-DD-YYYY | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-267317@lists.php.net to get a copy of this message | ||
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) ?$utime = strtotime($_POST['input']); if ( $utime !== false && $_POST['input'] == date('m-d-Y', $utime) ) { $mysql_date = date('Y-m-d', $utime); // valid date and format // use $mysql_date for whatever now } else error(); The above will take what ever is entered, as long as it is a valid date, and convert it to a timestamp. Then it converts it back to a date, formatted like the original. If they match, the it is valid. If they don't match, well then... -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare