I've been searching high and low for a regex that will validate MM/DD only. I do not need year (we're asking in a form for fiscal year ends, so we don't need a year, we need to know the range of their fiscal year).
For example, I need them to be able to enter 06/30 or 12/31 for Jun 30th or Dec 31st, respectively. All the regex examples I was able to find include the year as part of the date, which I do not need and I am very unfamiliar with regular expression syntax. What regex can I use for for two digit month and day only?
For all months (i.e. 28 days):
(0[1-9]|1[0-2])/([01][1-9]|10|2[0-8])
For all months apart from February:
(0[13-9]|1[0-2])/(29|30)
For months with 31 days (i.e.01, 03, 05,07, 08, 10 and 12)
(0[13578]|1[0-2])/31
Putting this together
((0[1-9]|1[0-2])/([01][1-9]|10|2[0-8]))|((0[13-9]|1[0-2])/(29|30))|((0[13578]|1[0-2])/31)
Then for leap years append the following to the regular expression
|02/29
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With