The following summarizes several ways to use php to verify whether the date entered by the user is the correct date. Friends in need can refer to it.
The checkdate() function verifies a Gregorian date.
Example
The code is as follows
代码如下 |
复制代码 |
var_dump(checkdate(12,31,2000));
var_dump(checkdate(2,29,2003));
var_dump(checkdate(2,29,2004));
?>输出:
bool(true)
bool(false)
bool(true)
|
|
Copy code
|
var_dump(checkdate(12,31,2000));
var_dump(checkdate(2,29,2003));
var_dump(checkdate(2,29,2004));
?>Output:
bool(true)
bool(false)
bool(true)
代码如下 |
复制代码 |
* 检查是否为一个合法的时间格式
*
* @param string $time
* @return void
*/
function is_time($time)
{
$pattern = '/[d]{4}-[d]{1,2}-[d]{1,2}s[d]{1,2}:[d]{1,2}:[d]{1,2}/';
return preg_match($pattern, $time);
}
|
Regular date
代码如下 |
复制代码 |
$reg="/d{4}-d{2}-d{2}/";
preg_match($reg,$days,$arr);
print_r($arr);
|
Example 1 |
/**
The code is as follows
|
Copy code
* Check if it is a legal time format
*
* @param string $time
* @return void */
function is_time($time)
{
$pattern = '/[d]{4}-[d]{1,2}-[d]{1,2}s[d]{1,2}:[d]{1,2}:[d ]{1,2}/';
return preg_match($pattern, $time);
}
Example 2
Regular verification date
The code is as follows
|
Copy code
|
$reg="/d{4}-d{2}-d{2}/";
preg_match($reg,$days,$arr);
print_r($arr);
http://www.bkjia.com/PHPjc/628963.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628963.htmlTechArticleThe following summarizes several ways to use php to verify whether the date entered by the user is the correct date. Friends in need Can be used for reference. The checkdate() function verifies a Gregorian date. Example...
|
|
|