I want to validate an user input.
The user is allowed to write all characters, digits and “_” or “-“.
I’m using
myString.search(/\W/) != -1
to validate.
It works for everything I want, but not for the “-“.
How can I search for “no wordcharacter” but the hyphen “-” is allowed?
The solution should be
myString.search(/[^\w-]/) != -1