Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, February 10, 2016

What html5 form attribute should be used for a zipcode?

What html5 form attribute should be used for a zipcode?


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

Answer by Md Johirul Islam for What html5 form attribute should be used for a zipcode?


You can try this

  

Answer by Shomz for What html5 form attribute should be used for a zipcode?


You can use either and the form will work. However, it might be a better idea to use number because, for example, mobile devices would invoke a different keyboard layout - with numbers and helper characters instead of the full alphanum keyboard.

But, if you think setting one type as opposed to another will offer a higher level of security, you're wrong. No matter which type you put, it will offer you no security. Every form input needs to be checked on the server as well - that's where the real security check happens. The check that you do in browser, is more of a UI/UX thing.

Here is a nice article about different input types: http://html5doctor.com/html5-forms-input-types/

Answer by Patrick Hofman for What html5 form attribute should be used for a zipcode?


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!

Answer by Jukka K. Korpela for What html5 form attribute should be used for a zipcode?


?Should? is a strong word, but there is actually a ?should? class statement about issues like this. HTML5 CR says about input type=number:

Note: The type=number state is not appropriate for input that happens to only consist of numbers but isn't strictly speaking a number. For example, it would be inappropriate for credit card numbers or US postal codes. A simple way of determining whether to use type=number is to consider whether it would make sense for the input control to have a spinbox interface (e.g. with "up" and "down" arrows).

The means that the only feasible element for the purpose is input type=text, when using built-in constructs. 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. For international postal addresses, you probably should not use any pattern or even maxlength, since the formats vary.

Answer by Andrew M for What html5 form attribute should be used for a zipcode?


If you have any international users you are going to want to allow alpha numeric via type="text"

Example: UK postal codes are formatted as AA9A 9AA

9 = any number

A = any letter


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.