How to block +,-,e in input type number using Javascript

Md Riyazuddin Verified
To block the +,-,e in input type number by using the following code.
<input type="number" id="input" />
<script>
var input = document.getElementById("input");

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

input.addEventListener("keydown", function(e) {
  if (invalidChars.includes(e.key)) {
    e.preventDefault();
  }
});
</script>


Comments

Leave a Comment