Regular Expression to match valid dates

后端 未结 15 2021
庸人自扰
庸人自扰 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

    If you're going to insist on doing this with a regular expression, I'd recommend something like:

    ( (0?1|0?3| <...> |10|11|12) / (0?1| <...> |30|31) |
      0?2 / (0?1| <...> |28|29) ) 
    / (19|20)[0-9]{2}
    

    This might make it possible to read and understand.

提交回复
热议问题