Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript replace string characters

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

function doValidate()
{
var valid = true;

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

return valid;   
}
like image 814
Doc Holiday Avatar asked Dec 28 '22 13:12

Doc Holiday


1 Answers

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

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

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

like image 161
August Lilleaas Avatar answered Jan 13 '23 14:01

August Lilleaas