Regular Expression to match a valid day in a date

后端 未结 10 1751
别那么骄傲
别那么骄傲 2020-12-11 01:45

I need help coming up with a regex to make sure the user enters a valid date The string will be in the format of mm/dd/yyyy

Here is what I have come up

10条回答
  •  暖寄归人
    2020-12-11 02:25

    I have been working with this some time and the best regex I've came up with is the following:

    \b(0)?(?(1)[1-9]|(3)?(?(2)[01]|[12][0-9]))\b|\b[1-9]\b
    

    It will match the following numbers:

    1 01 10 15 20 25 30 31
    

    It does not match the following:

    32 40 50 90
    

提交回复
热议问题