PHP date format Legality regular validation code _php tutorial

Source: Internet
Author: User
PHP date format Legality regular validation code this section PHP regular date tutorial, provides three kinds of validation user input date is not the correct date format Oh, two kinds are verified with regular date, one is to use Checkdate to verify.

PHP Tutorial Date format legality regular validation code

This PHP regular date tutorial provides three ways to verify that the date entered by the user is not the correct date format Oh, two is verified with a regular date, one is verified with checkdate.
*/
$days = Date ("y-m-d");

Method a regular validation date

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


Method two with Cehckdate verification

$k = Explode ('-', $days);
if (Checkdate ($k [1], $k [2], $k [0]))
{
echo $days, ' date valid ';
}
Else
{
Echo ' is not a valid date ';
}

Method three 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, ' for effective date ';
}
Else
{
Echo

' Invalid date ';
}

/*
About the Checkdate function

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

If the specified value is valid, the function returns True, otherwise false is returned.

The date is valid in the following cases:
Month is between and includes 1-12
The value of day is within the range of days that a given month should have, and leap years are taken into account.
Year is between and includes 1 to 32767


Verify format is month/day/year

This site original tutorial, reproduced annotated from www.bKjia.c0m/phper/php.html
*/

http://www.bkjia.com/PHPjc/632365.html www.bkjia.com true http://www.bkjia.com/PHPjc/632365.html techarticle PHP date format Legality regular validation code this section PHP regular date tutorial, provides three kinds of validation user input date is not the correct date format Oh, two kinds of is to use regular date verification, ...

  • 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.