admin管理员组

文章数量:1323679

I already am doing a replace for the mas in an textbox. How would I replace if there is an "$" and a ma also in the same line?

function doValidate()
{
var valid = true;

document.likeItemSearchForm.sup.value = document.likeItemSearchForm.sup.value.replace(/\,/g,''); 

return valid;   
}

I already am doing a replace for the mas in an textbox. How would I replace if there is an "$" and a ma also in the same line?

function doValidate()
{
var valid = true;

document.likeItemSearchForm.sup.value = document.likeItemSearchForm.sup.value.replace(/\,/g,''); 

return valid;   
}
Share edited Nov 26, 2020 at 19:17 peterh 1 asked Sep 26, 2011 at 13:35 Doc HolidayDoc Holiday 10.3k32 gold badges102 silver badges153 bronze badges 2
  • 2 Why do you escape the ma? It has no special meaning in a regex. – ThiefMaster Commented Sep 26, 2011 at 13:37
  • FYI, you should tag the answer as accepted if you find it adequate. – August Lilleaas Commented Oct 12, 2011 at 19:33
Add a ment  | 

1 Answer 1

Reset to default 10

Do you want to replace mas and dollar signs? Here's how:

"$foo, bar.".replace(/\$|,/g, "")

The regexp matches dollar signs or mas. The g flag tells it to match the entire string instead of stopping after the first match.

本文标签: regexJavascript replace string charactersStack Overflow