I understand why number inputs allow "e" or "E", but I'm confused as to why it allows multiple decimals.
If you look at the specification for valid floating-point numbers, you get:
A string is a valid floating-point number if it consists of:
- Optionally, a "-" (U+002D) character.
- One or both of the following, in the given order:
- A series of one or more ASCII digits.
- A single "." (U+002E) character.
- A series of one or more ASCII digits.
- Optionally:
- Either a "e" (U+0065) character or a "E" (U+0045) character.
- Optionally, a "-" (U+002D) character or "+" (U+002B) character.
- A series of one or more ASCII digits.
Everything I see here indicates that only a single decimal point should be allowed in the input, and that decimal has to be included before specifying an exponent with "e", and that there can only be one "e", regardless of case.
Yet, inputs such as these are allowed:
- 1.....2
- ......
- eeee........
- 1.0.0.01.0
And so on.
In IE 11, it'll let me type in whatever string I what, but unless it's a "valid" number the .value
is ""
. In this case, 1......e
is valid, but eeeeee
is not. If IE determines the value is not valid, then on focus away from the input the display blanks out, preventing the user from modifying the existing input.
In Chrome 51, it will only let me type digits, +/-, e/E and ".". When I check the value of input like 10.0.
with an extra decimal, it still returns the value of 10.0
, but if I type 10.0.0
or 10..
the string reverts to empty. Chrome will preserve displaying the invalid input.
When the strings become empty, it prevents doing further validation checks of the input and giving helpful user feedback.
So, why are multiple decimals allowed in the number input fields to begin with, and why are they handled so oddly between browsers?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…