HTML5 Input type=number removes leading zero

前端 未结 5 857
予麋鹿
予麋鹿 2020-12-02 20:05

In Chrome 15, when using the element as a text field, leading zeros (e.g. 011) are removed even if the number entered does not break the validation rules (e.g. min, max).

5条回答
  •  感动是毒
    2020-12-02 20:55

    The answer WHATWG provided me in IRC was that for non-numeric (e.g. not float/int) data that is numeric in nature, text is generally the correct type of input to use. The expection is if you are using something where a specific input type (e.g. telephone numbers, dates) already exists.

    input type=number should only be used for inputs that are literally numbers (int), and not data that uses numerals (such as postal codes).

提交回复
热议问题