0

In my VF page I have some Javascript to format passed variables. I have a string eg "Cost is $100.00" from which I need to remove all non-digit characters, EXCEPT the digital period. I want the result to be 100.00

I currently have:

var x = "Cost is $100.00";
var y = x.replace(/\D/g, '');

which removes all non-digit characters, including the "." What do I need to do to keep that?

4

You can write a negated character class with ^ to include the period, ., and the set of digits, 0-9:

var z = x.replace(/[^0-9.]/g, '');

z is then "100.00".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.