Reputation: 980
I'm trying to get the regular expression to work (using jQuery) for a specific pattern I need.
I need following pattern:
First two character
.
so, Strings like 01.2020
, 21.2020
, or 45.2020
have to match but 54.2020
or 04.2051
must not.
I tried to write the regex without the min and max requirement first and I'm testing the string using regex101.com but I'm unable to get it to work.
acording to the definition /^[0-9]{2}\.\d[0-9]{4}$/
should allow me to insert the strings in the format NN.NNNN
.
thankful for any input.
Upvotes: 0
Views: 36
Reputation: 15257
2 numbers from 00 to 53 can be matched using this : (?:[0-4][0-9]|5[0-3])
(00 -> 49 or 50 -> 53)
Character on position 3 needs to be a . : you've already got the \.
a number between 2010 and 2050 -> 20(?:[1-4][0-9]|50)
(20 followed by either 10 -> 49 or 50)
This gives :
(?:[0-4][0-9]|5[0-3])\.20(?:[1-4][0-9]|50)
Upvotes: 1