I have a text input where I want it to format while typing a value allowing 2 decimal places and 1000 separators. It should only allow digits. I have done the following but it does not allow adding decimal points. Simply put it is for entering the price of a product (currency).
INPUT = 1234560ABC.5665 (should only allow numbers)
EXPECTED = 1,234,560.56 (should limit decimal places to 2)
I have done the following but no idea how to add decimal values followed by a "." securing the "," 1000 separators.
<input type="text" id="price" name="price" />
$('#price').keyup(function (event) {
$(this).val(function (index, value) {
return '$' + value.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
});
});