i have a php methode that checks if a
passed in parameter is a date. Here's it:
public function is_Date($str){
if (is_numeric($str) || preg_match('^[0-9]^', $str)){
$stamp = strtotime($str);
$month = date( 'm', $stamp );
$day = date( 'd', $stamp );
$year = date( 'Y', $stamp );
return checkdate($month, $day, $year);
}
return false;
}
then, i test-drove it like this:
$var = "100%";
if(is_Date($var)){
echo $var.' '.'is a date';
}
$var = "31/03/1970";
if(is_Date($var)){
echo $var.' '.'is a date';
}
$var = "31/03/2005";
if(is_Date($var)){
echo $var.' '.'is a date';
}
$var = "31/03/1985";
if(is_Date($var)){
echo $var.' '.'is a date';
}
Note that each of the ifs also has an else statement
as
else{
echo $var.' '.'is not a date'
}
OUTPUT:
****100% is a Date
31/03/1970 is a Date
31/03/2005 is a Date
****31/03/1985 is a Date
My problem is, why is 100% displaying as a date and why
is 31/03/1985 not being read as a date ?
Any clue as to why will be highly appreciated as i am not
too expertise in Regex