user3297547 user3297547 - 2 years ago 172
Javascript Question

jQuery - replace multiple currency symbols from string

I hope this question isn't too basic.

I have a strings like

  1. "$1.11"

  2. "£1.50"

  3. "15,16 €"

Is it possible to remove the currency symbols like
character from the string within single
string.replace('$', '');

I don't want to use multiple cases or switch case.

Answer Source
var str = "$1.00, £2.00, €3.00";
var newStr = str.replace(/[\$£€]/g, '');

As you can see, you can use a regex expression to remove all the symbols.

It currently replaces $, £, and € - but if there are others you can add each individual symbol between the [square brackets]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download