can anybody here explain why input type=number
accepts e
character? it really confuses me and i'm wondering about it .
Asked
Active
Viewed 7,639 times
2 Answers
9
Because in addition to the letter e
, there is also a number e
(which represents exponents).
If you really want to exclude these, you can prevent them by targetting character code 69
, and preventing the default behaviour for the keypress
event with preventDefault()
if the character is entered:
document.querySelector("input").addEventListener("keydown", function(event) {
if (event.which === 69) {
event.preventDefault();
}
});
<input type="number">
EDIT Modified the event and the condition to event.preventDefault()
.

Romeo Sierra
- 1,666
- 1
- 17
- 35

Obsidian Age
- 41,205
- 10
- 48
- 71
8
e is the exponent. This allows a user to enter a number such as 4e3
, which means 4×103.
Try entering 4e3
in the box, and then press the up step button: in Chrome this will change to show 4001

BM-
- 616
- 5
- 15
-
hey, thanks for clear feedback! – curiosity Aug 28 '18 at 02:30