Re: validating mysql bound date

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

 



Larry Brown wrote:
Its been a long week already... YYYY-MM-DD.

On Tue, 2008-03-04 at 20:16 -0500, Larry Brown wrote:
Does anyone know if there is a builtin function for checking the
formatting of an incoming date to verify it is YYYY/MM/DD.  I know how
to convert between formats but want a quick way to check an incoming
variable to ensure it will be handled properly by mysqld.

I normally provide dropdown fields for each (except the year which is a text-field) and put it together how I need it. Validate each part separately and you're off and racing.

If you accept any date you'll probably have to split it up first but the principles will be the same.


$date = '0000-00-00';
// if they didn't use exactly two dashes? invalid
if (substr_count($date, '-') !== 2) {
  die("Invalid date");
}

list($year, $month, $day) = explode('-', $date);
if (strlen($year) != 4) {
  die("Invalid year");
}


and so on.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
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