PHP date format legality regular verification code_PHP tutorial

WBOY
Release: 2016-07-13 10:53:56
Original
945 people have browsed it

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632365.htmlTechArticlephp date format legality regular verification code This php regular date tutorial provides three ways to verify the date entered by the user Is it the correct date format? The second method is to use regular date verification...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template