note 12503 deleted from function.checkdate by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 20:38:29 +0000 |
| Subject: | note 12503 deleted from function.checkdate by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-21943@lists.php.net to get a copy of this message | ||
This is a function i wrote to check date formats in almost any format:
function checkdateformat($date, $format)
{
$format=str_replace("dd", "([0-9]{2})", $format);
$format=str_replace("d", "([0-9]{1,2})", $format);
$format=str_replace("mm", "([0-9]{2})", $format);
$format=str_replace("m", "([0-9]{1,2})", $format);
$format=str_replace("yyyy", "([0-9]{4})", $format);
$format=str_replace("yy", "([0-9]{2,4})", $format);
if (ereg($format, $date))
{return true;}
else
{return false;}
}
USAGE:
$date= the date you want to check.
$format= The format you want to compare the date against:
a 'd' or 'm' will allow 1 or 2 numbers
a 'dd' or 'mm' will only allow 2 numbers
a 'yy' will allow 2 to 4 numbers
a 'yyyy' will allow only 4 numbers
eg
$format=yyyy-mm-dd
$date=2001-04-18 TRUE
$date=01-04-18 FALSE
Currently there is no validation of the values in month or day.