I want allow comma (,) then replace to dot (.)
Like 45, then results is 45.
Comma don't must starting first.
Here is code:
<input id="number" value="" placeholder="" autofocus>
var input = document.getElementById('number');
input.onkeyup = input.onchange = enforceFloat;
//enforce that only a float can be inputed
function enforceFloat() {
var valid = /^\-?\d+\.\d*$|^\-?[\d]*$/;
var number = /\-\d+\.\d*|\-[\d]*|[\d]+\.[\d]*|[\d]+/;
if (!valid.test(this.value)) {
var n = this.value.match(number);
this.value = n ? n[0] : '';
}
}
https://jsfiddle.net/alumic/eon408z7/57/