Showing posts with label parens. Show all posts
Showing posts with label parens. Show all posts

Tuesday, July 28, 2009

javascript regex match on parens

Ugh, that was annoying. I needed to modify this line to also look for parens:
var re = new RegExp("^[a-zA-Z\.\'\,\-]*$", "g");

So I added it to the end, like so:
var re = new RegExp("^[a-zA-Z\.\'\,\-\(\)]*$", "g");

Let me add that I had already modified the server sie validation written in C# which looked almost the same, with no problem. But when I ran the page, the js choked and I got this error in the Error Console of my FF web dev toolbar (because I haven't tried Firebug yet...I know, what is wrong with me?)

"invalid range in character class"

What was this odd error? As far as I can tell, js does not like it if the last character before the ] in my RegExp expression is either ( or ). I moved them elsewhere, several elsewheres, just to see, and the error went away.

Ugh.