Reputation: 1897
How can I limit the length of a string matching a RegEx
I assumed that var sixCharsRegEx = /^.{6,7}/
would only match strings of lengths 6 or 7
but no: http://jsfiddle.net/FEXbB/
What am I missing?
Upvotes: 33
Views: 116426
Reputation: 175098
Match the start and the end.
var sixCharsRegEx = /^.{6,7}$/;
Upvotes: 9
Reputation: 5827
You are missing closing dollar at the end. Correct one is: /^.{6,7}$/
Upvotes: 56