开发者

Javascript replace string characters

开发者 https://www.devze.com 2023-04-08 08:44 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消