Tuesday, 15 September 2015

javascript - Regex date expression not working -



javascript - Regex date expression not working -

i have javascript function date validation.

var regex = new regexp(my regex look here); var result = regex.test(valuetotest);

however, i've been chasing tail lastly couple of hours because test returned false.

this not work ^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)\d\d$ not work ^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)\d{2}$ works ^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)[0-9]{2}$

the difference between 3 patterns final 2 digits. valid 3rd 1 returns true.

i'm trying understand if there i've done wrong, or whether there issues browser (firefox).

any ideas?

you putting these regexes string, in case "\d" beingness translated "d".

try using double slashes: "\\d"

however, must agree of other suggestions - don't utilize regex parsing dates. aren't suited job.

for example, look allow '31/02/1985' not date. in particular, run problems leap years (which occur every 4 years except 3 years within 400 year time span). seek matching regex!

javascript regex

No comments:

Post a Comment