A regular expression to match a valid date in the format YYYY-MM-DD. Date & Month validation is included.
/^[0-9]{4}-(((0[13578]|(10|12))-(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-(0[1-9]|[1-2][0-9]|30)))$/
Matches:
- 2021-12-17
- 2020-02-29
- 1002-03-04
Non-matches:
- 2021-17-12
- 2021-02-30