0

This code will replace the comma's no problem, but will leave the $ for some reason... Is it set up wrong? Trying to replace the $ also.

function doValidate() { 
    var valid = true;  
    document.likeItemSearchForm.sup.value = document.likeItemSearchForm.sup.value.replace(/\$|,/g, "")  
    return valid;   
}
2
  • "$,,$,$".replace(/\$|,/g, "") === "" for me. Commented Sep 26, 2011 at 14:57
  • what is going on with mine????? lol Commented Sep 26, 2011 at 15:01

2 Answers 2

2

Try this:

'asd$asd,asd,asd$,asd'.replace(/[\$,]/g,'');

JSFIDDLE -edit- fixed link

Sign up to request clarification or add additional context in comments.

2 Comments

You don't need \ inside a character class.
Thanks, didn't check the link (woops)
1

try this:

"$12,121.30".replace(/[\$,]/g, "");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.