PHP Check if it is a valid time format regular _php tutorial

Source: Internet
Author: User
The following summarizes several ways to use PHP to verify that the date entered by the user is the correct date Oh, a friend who needs to refer to the reference.

The Checkdate () function validates a trellis-high-date.

Example

The code is as follows 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)

Regular date

Example 1

/**

The code is as follows Copy Code

* Check if it is a valid 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

The regular validation 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.html www.bkjia.com true http://www.bkjia.com/PHPjc/628963.html techarticle The following summarizes several ways to use PHP to verify that the date entered by the user is the correct date Oh, a friend who needs to refer to the reference. The Checkdate () function validates a trellis-high-date. Example ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.