Issue
(/[a-zA-ZäöüÄÖÜ]{1,3}/.test(abc))
matches true
.
(/[a-zA-ZäöüÄÖÜ]{1,3}/.test(abcd))
also matches true
.
How can I test that it only returns true if there is a 1 to 3 Char, not 4?
Solution
Use the start (^
) and end ($
) anchors
function test(val) {
console.log(
'"%s": %s',
val,
/^[a-zA-ZäöüÄÖÜ]{1,3}$/.test(val)
// ^-------------------^ look here
);
}
test('ab');
test('abc');
test('abcd');
test('abcde');
Answered By - Daniel A. White
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.