javascript - JSLint issue in the code -
i facing wierd 2 jslint issues below code
function hasspecialchars(str){ return (/[~`@!#$%\^&*+=\-\[\]\\';,/{}()|\\":<>\?\s]/g).test(str);}
- unescape '/'
- wrap regex patterns /regexp/ disambiguate slash operator
i trying find special characters in string given.
you need use match function inorder find special characters.
str.match(/[~`@!#$%\^&*+=\-\[\]';,\/{}()|"\\:<>\?\s]/g)
and must escape forward slash.
to test atleast 1 special char.
/[~`@!#$%^&*+=\-\[\]';,\/{}()|"\\:<>?\s]/.test(str)
or
/\w/.test(str)
Comments
Post a Comment