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

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

python - Pygame screen.blit not working -

c# - Web API response xml language -