JavaScript Regex to check for certain characters
I am 开发者_运维技巧looking for a JavaScript function that checks for the following characters (without commas) in a string. If they are present, it would return false, else returns true.
<,>,(,),#,"",',:,::
function (str) {
return ! (/[<>()#':]|""/.test(str));
}
any set of single characters can put put inside a [set of brackets]. For longer patterns, use the pipe.
edit: as patrick pointed out, if you're checking for :
you don't need to check for ::
separately.
精彩评论