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

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

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

if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/))

Problem at line 398 character 41: Unescaped '^'.

if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/))

I understand that JSLint can be "overly cautious." I read comments on a similar issue, the JSLint option's purpose is "disable unsafe in regular expression" .

However, I would like to have the best of all worlds and have a working regex that also doesn't cause a JSLint complaint.

But I do not perform regex.

Is it possible to make a regular expression that looks for at least one special character, but does not cause a JSLint complaint?

+3
1

; (: ). , (^) (-) , .

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

. :

/\W/

, (a-zA-Z), (0-9) (_).

+3

Source: https://habr.com/ru/post/1765763/


All Articles