Is there a way to make JSLint happy with this regex?

后端 未结 1 343
故里飘歌
故里飘歌 2021-01-21 09:33

When running my JavaScript through JSLint, I get the following two errors from the same line of code.

Problem at line 398 character 29: Insecure \'.\'.

if (pass         


        
1条回答
  •  孤街浪徒
    2021-01-21 10:08

    That's a character class; you don't need a separator (eg: the commas). You can clean up the regex by placing the caret (^) and the dash (-) in strategic positions so they don't need to be escaped.

    /[!@#$%^&*?_~()-]/
    

    Should work. You can also use the non-word character class:

    /\W/
    

    That matches anything that's not a letter (a-zA-Z), number (0-9) or underscore (_).

    0 讨论(0)
提交回复
热议问题