Answers for "prevent user from typing e,+,- from number input"

0

prevent user from typing e,+,- from number input

<input type="number" id="inputBox" />
Posted by: Guest on November-18-2020
0

prevent user from typing e,+,- from number input

var inputBox = document.getElementById("inputBox");

var invalidChars = [
  "-",
  "+",
  "e",
];

inputBox.addEventListener("keydown", function(e) {
  if (invalidChars.includes(e.key)) {
    e.preventDefault();
  }
});
Posted by: Guest on November-18-2020

Browse Popular Code Answers by Language