The regular expression for the strongest verification date, which adds verification for the leap year.
This date Regular Expression supports
YYYY-MM-DD
Yyyy/mm/dd
Yyyy_mm_dd
Yyyy. Mm. dd format
Match: 2008-2-29 2008/02/29
Not match: 2008-2-30 2007-2-29
The complete regular expression is as follows:
(^ (1 [8-9] \ D {2}) | ([2-9] \ D {3 }))([-\/\. _]) (10 | 12 | 0? [13578]) ([-\/\. _]) (3 [01] | [12] [0-9] | 0? [1-9]) $) | (^ (1 [8-9] \ D {2}) | ([2-9] \ D {3 })) ([-\/\. _]) (11 | 0? [469]) ([-\/\. _]) (30 | [12] [0-9] | 0? [1-9]) $) | (^ (1 [8-9] \ D {2}) | ([2-9] \ D {3 })) ([-\/\. _]) (0? 2) ([-\/\. _]) (2 [0-8] | 1 [0-9] | 0? [1-9]) $) | (^ ([2468] [048] 00) ([-\/\. _]) (0? 2 )([-\/\. _]) (29) $) | (^ ([3579] [26] 00 )([-\/\. _]) (0? 2 )([-\/\. _]) (29) $) | (^ ([1] [89] [0] [48]) ([-\/\. _]) (0? 2 )([-\/\. _]) (29) $) | (^ ([2-9] [0-9] [0] [48]) ([-\/\. _]) (0? 2 )([-\/\. _]) (29) $) | (^ ([1] [89] [2468] [048]) ([-\/\. _]) (0? 2 )([-\/\. _]) (29) $) | (^ ([2-9] [0-9] [2468] [048]) ([-\/\. _]) (0? 2 )([-\/\. _]) (29) $) | (^ ([1] [89] [13579] [26]) ([-\/\. _]) (0? 2 )([-\/\. _]) (29) $) | (^ ([2-9] [0-9] [13579] [26]) ([-\/\. _]) (0? 2) ([-\/\. _]) (29) $ ))
A leap year has 29 days in February, so the regular expression that matches the leap year date format as YYYY-MM-DD is:
([0-9] {2}) (0 [48] | [2468] [048] | [13579] [26]) | (0 [48] | [2468] [048] | [3579] [26]) 00)-02-29
Finally, combine the expression of date verification for the Year of the year, we get the final validation date format for the YYYY-MM-DD of the regular expression is:
([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)
Regular Expression in DD/MM/YYYY format:
(0 [1-9] | [12] [0-9] | 3 [01])/(0 [13578] | 1 [02]) | (0 [1-9] | [12] [0-9] | 30)/(0 [469] | 11 )) | (0 [1-9] | [1] [0-9] | 2 [0-8])/(02 )) /([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 })) | (29/02/([0-9] {2}) (0 [48] | [2468] [048] | [13579] [26]) | (0 [48] | [2468] [048] | [3579] [26 )))