Regular Expression to match valid dates

后端 未结 15 2019
庸人自扰
庸人自扰 2020-11-22 04:48

I\'m trying to write a regular expression that validates a date. The regex needs to match the following

  • M/D/YYYY
  • MM/DD/YYYY
  • Single digit mon
15条回答
  •  执笔经年
    2020-11-22 05:22

    This regex validates dates between 01-01-2000 and 12-31-2099 with matching separators.

    ^(0[1-9]|1[012])([- /.])(0[1-9]|[12][0-9]|3[01])\2(19|20)\d\d$
    

提交回复
热议问题