views:

31

answers:

1

All,

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

<,>,(,),#,"",',:,::

Thanks

+4  A: 
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.

Jimmy
+1 for the negate.
patrick dw
@patrick Funny, I gave @nickf +1 because his *didn't* negate!
Josh
@Josh - I didn't catch this at first, but the request was specifically to return `false` if the character was found.
patrick dw
Although, it is a bit redundant to check for both `:` and `::` since you can't have the second without the first.
patrick dw
@patrick: good point :)
Jimmy