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;
}
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.
精彩评论