$ Days = date ("y-m-d ");
// Method 1 positive verification date
The code is as follows: |
Copy code |
$ Reg = "/d {4}-d {2}-d {2 }/"; Preg_match ($ reg, $ days, $ arr ); Print_r ($ arr ); |
// Method 2 use cehckdate for verification
The code is as follows: |
Copy code |
$ 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
The code is as follows: |
Copy code |
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.
Original tutorial on this site, reprinted with the source www.111cn.net/phper/php.html
*/