Php date format validity regular expression verification code _ PHP Tutorial

Source: Internet
Author: User
Tags php regular expression
Php date format validity regular expression verification code. Php date format legality regular expression verification code this php regular expression date tutorial provides three methods to verify whether the date entered by the user is in the correct date format, php date format legality regular expression verification code this php regular expression date tutorial provides three methods to verify whether the date entered by the user is in the correct date format, one is to use checkdate for verification.

Php Tutorial date format validity regular expression verification code

In this php regular date tutorial, three types of date formats are provided to verify whether the date entered by the user is in correct format. The two types are regular date verification and the other is checkdate verification.
*/
$ Days = date ("y-m-d ");

// Method 1 positive verification date

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


// Method 2 use cehckdate for verification

$ K = explode ('-', $ days );
If (checkdate ($ k [1], $ k [2], $ k [0])
{
Echo $ days, 'date valid ';
}
Else
{
Echo 'invalid date ';
}

// Method 3 simple and intuitive regular expression 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, 'valid date ';
}
Else
{
Echo

'Invalid date ';
}

/*
About the checkdate function

The checkdate () function verifies a greaguri date.

If the specified value is valid, the function returns true; otherwise, false.

The date is valid in the following cases:
The month value ranges from 1 to 12.
The value of day is within the range of days that a given month should have. a leap year has been taken into account.
Year between and includes 1 to 32767


The verification format is month/day/year.

This site's original tutorial, reprinted with the source www. bKjia. c0m/phper/php.html
*/

Success ,...

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.