javascript - regex cannot force exactly 11 digits -


this question has answer here:

i want force 11 digits, adding validator jquery validator plugin regex, problem allows more 11 , should not, should 11 exactly.

/[0-9]{11}$/.test(value); 

it not allow less 11 correct allow more not correct, should 11, no more no less.

you need add ^ match beginning of string: /^[0-9]{11}$/

that allow match exact, beginning end. current pattern match 11 numbers occurring @ end of string only. e.g., abc12345678901 considered valid.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -