javascript - regex cannot force exactly 11 digits -
this question has answer here:
- matching 10 digits in javascript 3 answers
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
Post a Comment