|
Checks if a string is a valid date in the format dd/mm/yyyy.
Could easily be adapted to check for other formats or the ereg a little
less strict i.e. allow 1/8/2001. One improvement could be a second
parameter passed in with the actual date format to be checked for(e.g
if(isDate($strDate, $strDateFormat))
{
...
}
PHP functions used: ereg(), explode() and checkdate()
-
<?php
-
/***********************************************************************
-
* function isDate
-
*
-
* boolean isDate(string)
-
* Summary: checks if a date is formatted correctly: dd/mm/yyyy (european)
-
* Author: Laurence Veale
-
* Date: 30/07/2001
-
***********************************************************************/
-
function isDate($i_sDate)
-
{
-
$blnValid = TRUE;
-
// check the format first (may not be necessary as we use checkdate() below)
-
if(! ereg ("^[0-9]{2}/[0-9]{2}/[0-9]{4}$", $i_sDate))
-
{
-
$blnValid = FALSE;
-
}
-
else //format is okay, check that days, months, years are okay
-
{
-
$arrDate = explode("/", $i_sDate); // break up date by slash
-
$intDay = $arrDate[0];
-
$intMonth = $arrDate[1];
-
$intYear = $arrDate[2];
-
-
$intIsDate = checkdate($intMonth, $intDay, $intYear);
-
-
if(!$intIsDate)
-
{
-
$blnValid = FALSE;
-
}
-
-
}//end else
-
-
return ($blnValid);
-
} //end function isDate
-
?>
|