I’m trying to validate mm-dd-(2012~2099) date format.
I have the following regular expression.
^(0[1-9]|1[0-2])-(0[1-9]|[10-31])-(20[12-99])$
when I run the following code, I get false. What’s wrong with this regular expression?
var reg = new RegExp("^(0[1-9]|1[0-2])-(0[1-9]|[10-31])-(20[12-99])$")
reg.test("05-33-2012")**
When I take out the year part, and then test “05-33”, it works.
As Oli said, [12-99] does not do what you think it does.
Specifically, the
-refers to a range of characters, not numbers. So[12-99]matches…The expression
20(1[2-9]|[2-9][0-9])would work for dates 2012-2099