javascript - JSLint issue in the code -


i facing wierd 2 jslint issues below code

function hasspecialchars(str){ return (/[~`@!#$%\^&*+=\-\[\]\\';,/{}()|\\":<>\?\s]/g).test(str);} 
  1. unescape '/'
  2. 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

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -