Reputation: 4441
It took me a while to find the answer to MM/DD including Leap Year (Feb 29th).
So I figured I'd make a question and answer my own question for other's to view.
Upvotes: 0
Views: 83
Reputation: 9460
Reg ex that matches all valid dates including leap years. Formats accepted mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy format
^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
Upvotes: 1
Reputation: 4441
Use the following
^((0?[1-9]|1[012])\/(0?[1-9]|1\d|2[0-9])|(0?[13456789]|1[012])\/(29|30)|(0?[13578]|1[02])\/31)$
Upvotes: 1