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