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 around all the different attributes with the forms in html5. Cheers
You can use the maxlength attribute to set the maximum number of characters (works on all browsers) and additionally a pattern attribute what specifies the allowed characters and combinations, too; its value naturally depends on the zipcode type(s) to be used.
HTML input fields used for Zip Codes should be type=text and use the pattern attribute to provide hints to the browser · GitHub.
The most complete ZIP Code is a nine-digit number consisting of five digits, a hyphen, and four digits, which the USPS describes by its trademark ZIP+4. The correct format for a numeric ZIP+4 code is five digits, a hyphen, and four digits.
You can try this
<Label>ZIP Code</Label><input type="text" pattern="[0-9]{5}" title="Five digit zip code" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With