What html5 form attribute should be used for a zipcode?

前端 未结 8 2039
我寻月下人不归
我寻月下人不归 2021-02-01 02:51

Is it best to use a \'text\' attribute with a limit on the number of characters, or can I use a number attribute in an input for a zipcode.

Just trying to get my head ar

8条回答
  •  时光取名叫无心
    2021-02-01 03:24

    "Best" is subjective/contextual. But from a usability perspective, Zach Leatherman studied number-ish inputs in 2016 and specifically addressed the ZIP input.

    The goal was to make "big number keyboards" appear on mobile devices. This may seem insignificant, but easing form input in e-commerce checkout forms is an important goal.

    It seems that some day the inputmode="numeric" attribute will be appropriate for zip inputs. But for now, only Chrome/Android supports it (Firefox has it behind a flag).

    Zach developed a small library called numeric-input as part of his formcore package which will implement the best possible case for whatever browser is being used.

    Keep in mind, the library is a couple years old, and browser behavior might have changed since then.

提交回复
热议问题