php date format legality regular verification code This PHP regular date tutorial provides three date formats to verify whether the date entered by the user is correct. The second is to use regular date verification, and the other is to use checkdate to verify.
php tutorial date format legality regular verification code
This PHP regular date tutorial provides three date formats to verify whether the date entered by the user is correct. The second is to use regular date verification, and the other is to use checkdate to verify.
*/
$days = date("y-m-d");
//Method 1 regular verification date
$reg="/d{4}-d{2}-d{2}/";
preg_match($reg,$days,$arr);
print_r($arr);
//Method 2 uses cehckdate to verify
$k = explode('-',$days);
if( checkdate($k[1],$k[2],$k[0]) )
{
echo $days,'date is legal';
}
else
{
echo 'Not a valid date';
}
//Method 3 simple and intuitive regular verification
if( ereg("(19|20)[0-9]{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][ 0-9]|3[01])$",$days))
{
echo $days,'is a valid date';
}
else
{
echo
'Invalid date';
}
/*
About checkdate function
The checkdate() function verifies a Gregorian date.
If the specified value is legal, the function returns true, otherwise it returns false.
Dates are legal if:
month is between and including 1 - 12
The value of day is within the range of days that a given month should have, taking leap years into account.
year is between and including 1 to 32767
The verification format is month/day/year
Original tutorial on this site, reprinted from www.bKjia.c0m/phper/php.html
*/