Why input type = number allows multiple decimal places?

I understand why numeric inputs allow "E" or "E" , but I'm confused about why it allows a few decimal places.

If you look at the specification of valid floating point numbers , you will get:

A string is a valid floating point number if it consists of:

  • Optionally, the "-" character (U + 002D).
  • One or both of the following, in this order:
    • A series of one or more ASCII digits.
      • One single. (U + 002E).
      • A series of one or more ASCII digits.
  • Not necessary:
    • Either the character "e" (U + 0065), or the character "E" (U + 0045).
    • Optional character "-" (U + 002D) or "+" (U + 002B).
    • A series of one or more ASCII digits.

Everything that I see here indicates that only one decimal point should be allowed in the input file and that the decimal value must be included before the exponent is indicated with "e" and that there can only be one "e", regardless of , a business.

However, input data such as:

  • 12
  • ......
  • uh ........
  • 1.0.0.01.0

And so on.

In IE 11, it will allow me to enter any string I, but if it is not a "valid" .value number, it is "" . In this case, 1......e valid, but eeeeee is not. If IE determines that the value is invalid, then when focusing from the input, the display fades, preventing the user from changing the existing input.

In Chrome 51, it allows me to enter the numbers +/-, e / E and ".". When I check the input value as 10.0. with an additional decimal number, it still returns 10.0 , but if I 10.0.0 or 10.. , the line will return to empty. Chrome will keep displaying invalid input.

When strings become empty, this prevents further validation checks from entering input and provides useful user feedback.

So why are multiple decimal places allowed in number input fields, and why are they so weirdly handled between browsers?

+6
source share
1 answer

I dug a little, and I have a hunch that this might be a mistake in implementing quantity input in Chrome.

Here is a set of changes in which they corrected which characters were allowed in entering the type number.

This line should be noted:

 event->setText(locale().stripInvalidNumberCharacters(event->text(), "0123456789.Ee-+")); 

This means that 0123456789.Ee-+ is all legal characters according to Chrome. Everything else is removed, but these characters are allowed. However, it is not checked whether the input value is really a real actual number, and you can enter meaningless strings consisting of these characters, and these strings are still considered valid (for example, +++111ee... or ++++ or ...+++...+++...+++123321 or something like that.

In the original ticket for the entry number, which allows any characters, it seems that this may be the author’s goal. You can check the original problem on the Chromium tracker .

In any case, it might be worth adding a bug report to the Chromium project so that they know that something funky is happening.

+2
source

All Articles