Php check for a valid time format regular _ PHP Tutorial

Source: Internet
Author: User
Php checks whether it is a valid time format regular. The following summarizes several methods of verifying whether the date entered by the user is correct using php. if you need it, refer to it. The checkdate () function verifies a greaguri date. The example below summarizes several methods of using php to verify whether the date entered by the user is the correct date. For more information, see.

The checkdate () function verifies a greaguri date.

Example

The code is as follows:

Var_dump (checkdate (12, 31, 2000 ));
Var_dump (checkdate (2003 ));
Var_dump (checkdate (2004 ));
?> Output:

Bool (true)
Bool (false)
Bool (true)

Regular date

Example 1

/**

The code is as follows:

* Check whether 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

Regular expression verification date

The code is as follows:

$ Reg = "/d {4}-d {2}-d {2 }/";
Preg_match ($ reg, $ days, $ arr );
Print_r ($ arr );

Bytes. The checkdate () function verifies a greaguri date. Example...

Related Article

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.