Regular Expression to match valid dates

后端 未结 15 1839
庸人自扰
庸人自扰 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 04:58

    This is not an appropriate use of regular expressions. You'd be better off using

    [0-9]{2}/[0-9]{2}/[0-9]{4}
    

    and then checking ranges in a higher-level language.

提交回复
热议问题