Reputation: 43
console.log(/^[0-9a-zA-Z]+[~!@#$%^&*_+-=]+$/.test("123456"));
I think it should return false
because the string does not end with a ~!@#$%^&*_+-=
character,
but it returns true
when it runs.
Why does it return true
?
Upvotes: 3
Views: 49
Reputation: 85767
The problem is that +-=
is a range. If you look at the ASCII table, you can see that +-=
includes +
, -
, .
, /
, :
, ;
, <
, =
, and all digits 0
.. 9
.
You want [~!@#$%^&*_+\-=]
(escape the -
).
Upvotes: 6