An input element contains numbers a where comma or dot is used as decimal separator and space may be used to group thousands like this:
\'1,2\'
Here is my solution that doesn't have any dependencies:
return value
.replace(/[^\d\-.,]/g, "") // Basic sanitization. Allows '-' for negative numbers.
.replace(",", ".") // Change all commas to periods.
.replace(/\.(?=.*\.)/g, ""); // Remove all periods except the last one.
(I left out the conversion to a number - that's probably just a parseFloat call if you don't care about JavaScript's precision problems with floats.)
The code assumes that: