The code is as follows |
Copy Code |
$arr _date = Array ( ' 2004-06-01 ', ' 2005-0x-10 ', ' 12-12-12 ', ' 2000-12-25 00:10:20 ', ' 2007-12-05 ' ); for ($i =0; $i <5; + + $i) { $date = $arr _date[$i]; if (Ereg ([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}), $date, $regs)) { echo "date string $date conforms to ' YYYY-MM-DD ' format:"; echo "$regs [1]. $regs [2]. $regs [3]<br/><br/>"; } Else { echo "<b> date string $date does not conform to the ' YYYY-MM-DD ' format date string </b><br/><br/>"; } } |
Matching YYYY-MM-DD
The code is as follows |
Copy Code |
([0-9]{3}[1-9]| [0-9] {2} [1-9] [0-9] {1}| [0-9] {1} [1-9] [0-9] {2}| [1-9] [0-9] {3}) -((0[13578]|1[02])-(0[1-9]|[ 12][0-9]|3[01]) | ((0[469]|11)-(0[1-9]|[ 12][0-9]|30)) | (02-(0[1-9]|[ 1][0-9]|2[0-8])) | (([0-9]{2}) (0[48]|[ 2468][048]| [13579] [26]) | ((0[48]| [2468] [048]| [3579] [26]) 00))-02-29) |
2: Matching dd/mm/yyyy or matching d/m/yyyy
The code is as follows |
Copy Code |
'/^ ([0-9]{3}[1-9]| [0-9] {2} [1-9] [0-9] {1}| ' .' [0-9] {1} [1-9] [0-9] {2}| [1-9] [0-9] {3}) /(([13578]|1[2]) | (0[13578]|1[02]) ' .' /((0[1-9]| [12] [0-9]|3[01]) | ([1-9]| [12] [0-9]|3[1])) | ((0[469]|11) | ([469]|11)] ' .' /((0[1-9]| [12] [0-9]|30) | ([1-9]| [12] [0-9]|30)] | ' .' ((02|2)/((0[1-9]|[ 1][0-9]|2[0-8]) | ([1-9]| [1] [0-9]|2[0-8])) ' .')))| ((([0-9]{2}) (0[48]|[ 2468][048]| [13579] [26]) | ([48]| [2468] [048]| [13579] [26]) | ' .' ((((0[48]) | ([48]) | [2468] [048]| [3579] [26]) 00))/(02|2)/29) $/'; |