Add to collection
Md Riyazuddin

Md Riyazuddin

Verified

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

To block the +,-,e in input type number by using the following code.

Try Yourself in Code Editor    


<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>
Tagged with: Javascript HTML

Comments 0

  • Sorry!! No comment posted yet. Become the first user to give comment.
Add a comment

Would you like to write for w3 sniff?

Become part of an amazing group of contributors and authors and start writing for us

Join Now
<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>
Feedback submitted successfully.