Why does input type=number allow multiple decimals?

后端 未结 1 2019
梦如初夏
梦如初夏 2020-12-16 17:27

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-po

相关标签:
1条回答
  • 2020-12-16 18:04

    I did some digging, and I have a hunch that this may be a bug in Chrome's implementation of the number input.

    Here's the changeset where they fixed which characters were allowed in an input of type number.

    Of note is this line:

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

    That means that 0123456789.Ee-+ are all legal characters according to Chrome. Everything else gets stripped out, but those characters are allowed through. However, there's no checking on whether or not the value of the input is a real actual number and you can enter nonsensical strings made up of those characters and have those strings still be considered valid (e.g. +++111ee... or ++++ or ...+++...+++...+++123321 or anything like that).

    In the original ticket for the issue of number inputs allowing any characters, it seems this might be the author's intent. You can check the original issue on Chromium's issue tracker.

    Either way, it might be worth filing a bug report with the Chromium project to let them know that something funky is going on.

    0 讨论(0)
提交回复
热议问题