user3850712
user3850712

Reputation: 123

Jquery Remove special symbol

How can I remove £ from a string. I was trying this:

price = data.salesPrice;
price = price.replace(/\^£/,"");
console.log(price);

but still I was receiving like this: £22.80. I tried with parseInt but it's return NaN. Any idea please ?

Upvotes: 1

Views: 1065

Answers (4)

Lix
Lix

Reputation: 47966

I am assuming (from your regex attempt) that your objective here is to remove the pound symbol (£) from the beginning of a string.

You are escaping the caret symbol in your regex. This means you want to match a literal ^ and not use it to indicate the beginning of a string. Remove that escaping and your regex will work as expected.

price = price.replace(/^£/,"");

Upvotes: 5

Ash
Ash

Reputation: 2595

Use unicode in this case

  price.replace(/\u00A3/g, '');

Upvotes: 0

Samuli Hakoniemi
Samuli Hakoniemi

Reputation: 19049

I'd go with regexp removing all the other characters except numbers (and dot):

var price = "£22.80";
price = price.replace(/\D*/, "")

Upvotes: 5

Sudharsan S
Sudharsan S

Reputation: 15393

Try

price = "£22.80";
price = price.replace("£" ,"");
console.log(price);

DEMO

Upvotes: 0

Related Questions