Alex Rivera | Logout

RegEx for maximum length in JavaScript

Asked 2012-07-16T19:26:15.183
33

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?

Edit
Report

1 Answer

9

Match the start and the end.

var sixCharsRegEx = /^.{6,7}$/;

Your improved example

answered 2012-07-16T19:27:47.493

Your Answer