The regular expression for date verification provides three regular expressions for date verification. You can select one of the following three methods for date Verification Based on your needs.
Regular Expression for date Verification
The following provides three regular expressions for date verification. You can select one of the following three methods for date Verification Based on your needs.
*/
$ Arr_date = array (
'2017-06-01 ',
'2017-0x-10 ',
'12-12-12 ',
'2017-12-25 00:10:20 ',
'2017-2007'
);
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 "the date string $ date conforms to the 'yyyy-mm-dd' format :";
Echo "$ regs [1]. $ regs [2]. $ regs [3] <br/> ";
}
Else
{
Echo "<B> the date string $ date does not conform to the date string in 'yyyy-mm-dd' format </B> <br/> ";
}
}
// Match with yyyy-mm-dd
([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: Match dd/mm/yyyy or d/m/yyyy
'/^ ([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) | ([1, 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) $ /';