Re: checking user input of MM-DD-YYYY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jan 15, 2008 11:25 AM, Adam Williams <awilliam@xxxxxxxxxxxxxxxx> wrote:
> Thanks, I think I have it:
>
> $dateexplode = explode("-", $_POST["date_entered"]);
> if (!preg_match("/^(\d{2})$/", $dateexplode[0],$data1) ||
> !preg_match("/^(\d{2})$/", $dateexplode[1],$data2) ||
> !preg_match("/^(\d{4})$/", $dateexplode[2],$data3))
>         {
>         die ("you have entered an invalid date");
>         }
>
> so if the person enters 01-15-2008 its fine, but 1-15-2008 dies.
>

Just curious why you won't take 1-15-2008. Once you validate it, you
can always assign it to a variable as either a timestamp or a DateTime
object and then format it however you want when you display it, send
it to a database, or whatever you are doing with the date.

FWIW, what you have above will also accept 42-75-2008.

Andrew

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux