jQuery remove all characters but numbers and decimals
问题 var price = "$23.03"; var newPrice = price.replace('$', '') This works, but price can also be such as: var price = "23.03 euros"; and many many other currencies. Is there anyway that I could leave only numbers and decimal(.)? 回答1: var newPrice = price.replace(/[^0-9\.]/g, ''); No jQuery needed. You will also need to check if there is only one decimal point though, like this: var decimalPoints = newPrice.match(/\./g); // Annoyingly you have to check for null before trying to // count the