开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜