Javascript replace with expression

Hi guys,

I’m working on a function that I want to remove speical charcters from. it currently looks like this:


var r={'special':/[\W]/g}
function iChars(obj,w){
  obj.value = obj.value.replace(r[w],'');
}

it works great, but I want to keep certain characters such as ’ " : _ - ,, basically quotation marks, colons and spaces. Where as my current script removes all special charcters. I know it can be done with php, but i’m working on something when it’s on a keyup/blur etc.

So is there a way or expression to make it so I can exclude certain characters from my expression? Or does someone else have anything they would recommend?

I’m new to character expressions, but any help would be greatly appeciated :slight_smile: Thanks.