I’m using the following regular expression to match one or more special characters for a password strength test.
if (password.match(/\W+/)) points++;
This doesn’t seem to match the underscore ‘_’ as a special character. Why is this and how can I fix it?
It is because
\Wis the same as[^\w], while\wcontainsa-z,A-Z,0-9, and_as well.In order to fix it just add
_character separately: