Quiero restringir la entrada del usuario a dos decimales solo al mismo tiempo restringir la entrada del usuario no mayor que el valor máximo. Mi código a continuación no funciona en conjunto.
Código JS
var validate = function(e) { var t = e.value; e.value = (t.indexOf(".") >= 0) ? (t.substr(0, t.indexOf(".")) + t.substr(t.indexOf("."), 3)) : t; } var input = document.getElementById("amt"); // Add event listener input.addEventListener("input", function(e){ var max = parseFloat(input.max); this.setCustomValidity(""); console.log(this.value) if(parseFloat(this.value) > max){ this.value = max; } else if(this.validity.rangeUnderflow){ this.setCustomValidity("Does not reach the amount requirement"); } });código HTML
<input type="number" min="100" max="999.99" step=".01" name="amt" id="amt" oninput="validate(this)" required>