-5

In an <input type="number">, I can type the following invalid input in Chrome:

  1. Type 11,
  2. Move the caret in the middle between both 1s,
  3. Type -.

However, I cannot type this invalid input:

  1. Type 1e,
  2. Move the caret in the middle between the 1 and the e,
  3. Press -; it won’t be typed.

But both of these values are invalid: input.value is the empty string.

What is the logic behind this behavior?

Example below for you to type numbers:

addEventListener("input", ({ target: { value } }) => document.querySelector("p").textContent = value);
<input type="number"/>
<p></p>
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
  • "Where i can read what the logic behind that?" Read the source code of the engine?? – epascarello Dec 28 '21 at 16:01
  • @epascarello this's is not an easy task to do. Chromium repository is huge. if you know what file or folder i should look please provide path – Alexander Pleshakov Dec 28 '21 at 16:12
  • Okay, now the question is clear, but _why does it matter_? These are invalid inputs anyway. By the way, Firefox allows typing these characters. – Sebastian Simon Dec 28 '21 at 16:27
  • @SebastianSimon Thatk you for editing the question. I'm just curious why it work like that. Firefox allow to type all characters. – Alexander Pleshakov Dec 28 '21 at 16:29
  • 1
    @Teemu No, both follow the standard. _“A control’s value is its internal state. As such, it might not match the user’s current input. For instance, if a user enters the word `"three"` into a numeric field that expects digits, the user’s input would be the string `"three"` but the control’s value would remain unchanged.”_ — From the definition of [value](//html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-value). How user agents deal with the user’s _keyboard input_ seems underspecified, but this is just a UI / UX issue that isn’t related to HTML itself. – Sebastian Simon Dec 28 '21 at 16:50
  • @SebastianSimon Thanks for clarifying, the standard texts are sometimes a nightmare to read and understand. – Teemu Dec 28 '21 at 16:59

1 Answers1

-2

Change the type of input to "text" if you want to write these characters on tag p.

The E stands for the exponent, and it is used to shorten long numbers. Since the input is a math input and exponents are in math to shorten great numbers, so that's why there is an E.

It is displayed like this: 4e.

if you want to block these characters, you can do this.

You can read more Here about exponential

Walter Junior
  • 122
  • 1
  • 6