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
Simpler regex:
([12]\d|3[01]|0?[1-9])
Consider the accepted answer and this expression:
(0[1-9]|[12]\d|3[01])
This matches 01 but not 1
The other expression in the accepted answer:
([1-9]|[12]\d|3[01])
This matches 1 but not 01
It is not possible to add an OR clause to get them both working.
The one I suggested matches both. Hope this helps.