Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  23] [ 2]  / answers: 1 / hits: 17274  / 14 Years ago, fri, november 5, 2010, 12:00:00

JSLint reports Insecure '^' for the following line. Why is that? Or is it just going to complain any time I want to negate a character class?



// remove all non alphanumeric, comma and dash characters
!$7s-gd,&j5d-a#.replace(/[^w,-]/g, '');

More From » regex

 Answers
88

It only will do this if you have the option selected at the bottom:



Disallow insecure . and [^...] in /RegExp/


From the docs:




true if . and [^...] should not be allowed in RegExp literals. These forms should not be used when validating in secure applications.




So the answer your question, if you start a regex with ^ and it's checked, yes it'll throw the error every time. The issue is with unicode characters, you're allowing pretty much anything in there and there's potential for security issues, or validation bypassing issues. Instead of disallowing something (which can be bypassed), allow only what characters are valid.


[#95063] Wednesday, November 3, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cayden

Total Points: 314
Total Questions: 107
Total Answers: 101

Location: Slovenia
Member since Wed, Apr 6, 2022
2 Years ago
;