Click to See Complete Forum and Search --> : Using Replace Function


mh53j_fe
10-23-2003, 11:35 AM
I have one more question for today. I have several text boxes where I need to strip out single (') and double (") quotes and replacing them with a space. I have no problem doing that when I am only looking for a single quote or a double quote, but I can't seem to get the syntax right for looking for two characters.
Here is my code:


field.value = l_field_value.replace(/'/g," ");


//Obviously, this works fine for single quotes only. How do I look for single and double quotes and replace both with spaces?

Thanks to all (especially Charles) for your help.

Dave

requestcode
10-23-2003, 12:40 PM
You could try this:
<script language="JavaScript">
function keyr(obj)
{
restr=obj.value
newstr=restr.replace(/\'|\"/g," ")
obj.value=newstr
}
</script>

Then call it like this:
<input type="text" name="txta" size="30" maxlength="30" onchange="keyr(this)">

The "|" character means single quote OR double quote.