I'm working on an Angular 4 project. I have an HTML <input type="number"> with min max and step attributes. My goal is to prevent typing numbers beyond the min-max range that is user friendly. How can I do that?
function myFunction(e) { var min = -100; var max = 100; var txtValue = document.getElementById("txt").value; var pressedValue = e.key; var combined = parseFloat(txtValue, pressedValue); console.log(`OLD:${txtValue}\nNEW:${pressedValue}\nCOMBINED:${combined}`); if (combined > max) { e.preventDefault(); console.log('ohhw snapp'); } } <input type="number" id="txt" value="Hello" onkeydown="myFunction(event)" min="-100" max="100" step="0.05">