What html5 form attribute should be used for a zipcode?

前端 未结 8 2036
我寻月下人不归
我寻月下人不归 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:14

    There are various options from my POV, but I think the best is already given by Md Johorul Islam: the pattern attribute.

    The options:

    • Use a regular expression (the pattern attribute);
    • Use a custom (jQuery) mask control, like jQuery mask;
    • For the platforms where this is not supported, use type=text with a maxlength.

    Note: Despite these options: always validate server side!

提交回复
热议问题