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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to