开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜