Default To The Numeric, Email, And URL Keyboards On The iPhone

Posted September 29, 2009 at 8:58 AM

Tags: HTML / CSS

A long time ago, it used to work on the iPhone Safari browser that if your form inputs had the term "zip" or "phone" in the form field name, clicking on it would default the resultant iPhone keyboard to a numeric keyboard. While this forced us to use some really poor naming conventions, it increased the usability of our web-based iPhone applications in a very palpable way, removing unnecessary clicks for data entry. Unfortunately, this feature was lost somewhere among the many subsequent iPhone firmware updates.

It felt like all was lost and there was no hope... until now. Dorinake, in the comments of my previous post, just explained that if he changed the Type attribute of his form inputs to "number" then he would get the numeric keyboard on the iPhone browser. I also confirmed this, and after doing a bit more testing, it looks like the iPhone now (in the latest firmware updates) supports a small sub-set of the HTML 5 input types:

  • Number
  • Email
  • Url

To test this, I set up a tiny sample page to see how each of these input Types would default the keyboard on the iPhone:

 Launch code in new window » Download code as text file »

  • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  • <html>
  • <head>
  • <title>Defaulting The iPhone Keyboard To: Number, Email, Url</title>
  • </head>
  • <body>
  •  
  • <h1>
  • Defaulting The iPhone Keyboard To: Number, Email, Url
  • </h1>
  •  
  • <form>
  •  
  • Type="Number":<br />
  • <input type="number" /><br />
  • <br />
  •  
  • Type="Url":<br />
  • <input type="url" /><br />
  • <br />
  •  
  • Type="Email":<br />
  • <input type="email" /><br />
  •  
  • </form>
  •  
  • </body>
  • </html>

As you can see, the Type attributes of the above Input fields are Number, Url, and Email respectively. When I open this page on my iPhone browser and click on the individual form fields, here are the keyboards that I get:

iPhone Input Type="Number"

 
 
 
 
 
 
Using Type = Number Defaults The iPhone Keyboard To The Numeric Keyboard. 
 
 
 

iPhone Input Type="Url"

 
 
 
 
 
 
Using Type = URL Defaults The iPhone Keyboard To The URL Keyboard. 
 
 
 

iPhone Input Type="Email"

 
 
 
 
 
 
Using Type = Email Defaults The iPhone Keyboard To The Email Keyboard. 
 
 
 

This is so awesome! And, what's great is that any browser that doesn't recognize these new HTML 5 input types will simply treat the input as a Text input. As such, this is completely backwards compatible. After discussing this insight with some people, it seems that even on the some of the most up-to-date phones, there are people who are not seeing the appropriate keyboards; we're not sure why this is happening but, there's certainly no harm in putting in the appropriate input types in the meantime.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page


You Might Also Be Interested In:




Reader Comments

Sep 29, 2009 at 9:10 AM // reply »
235 Comments

Woot. Thanks for sharing this. I wonder if Apple updated their docs? The last time I did research into this, they _did_ have decent documentation about writing web apps for the iPhone, so I'd be willing to bet they have this documented.


Sep 29, 2009 at 9:15 AM // reply »
7,572 Comments

@Raymond,

Would you mind posting a link the docs? I am not sure where they are.


Sep 29, 2009 at 9:16 AM // reply »
7,572 Comments

What's exciting about this is that due to the MMS updates, I am sure most everyone is going to be updating their iPhones; which means, most people will get this updates.


Sep 29, 2009 at 9:19 AM // reply »
235 Comments

Will do - I'm in the middle of my own blog post though. ;)


Sep 29, 2009 at 9:20 AM // reply »
7,572 Comments

@Raymond,

No worries :)


Sep 29, 2009 at 9:30 AM // reply »
188 Comments

I thought we had this worked out between you two? No overlapping blog authoring. Whomever goes first, must wait at least 30 minutes before the next person can start authoring their post. Sheesh.


Sep 29, 2009 at 9:32 AM // reply »
235 Comments

"There can be only one."

I'm looking now Ben. I'm now remembering how much of a pain in the ass Apple's site is. I can say that it does NOT require the 99 dollar program fee. Digging now.


Sep 29, 2009 at 9:33 AM // reply »
235 Comments

Well I found it:

http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html

But while it mentions some special stuff in forms, it does not mention what you found.


Sep 29, 2009 at 9:37 AM // reply »
7,572 Comments

@Todd,

HA ha.

@Raymond,

Awesome! I don't think I've every seen that page AND I have actually tried to find good documentation on this stuff (granted via Google rather than Apple's site). Thanks.


Sep 29, 2009 at 9:40 AM // reply »
235 Comments

More data:

http://ajaxian.com/archives/html5-features-in-latest-iphone-application-cache-and-database

FYI, the db stuff is incredibly cool and no one (that I know of) is working with this yet. It's much like the db support for AIR, but the browser itself supports it. I've meant to look into it, but haven't yet.

The second item described there looks to be real nice for web based HTML apps for the iPhone.


Sep 29, 2009 at 9:42 AM // reply »
235 Comments

More URLs: The db stuff is freaking incredible: http://blog.bemoko.com/2009/09/16/cool-iphone-handles-the-html5-onstorage-event-handler/


Sep 29, 2009 at 9:43 AM // reply »
7,572 Comments

@Raymond,

Awesome stuff! I'll definitely be looking into it.... when I can find the time :(


Sep 29, 2009 at 9:46 AM // reply »
235 Comments

Last URL, I promise. ;) The Safari in the newest iPhone also supports geolocation:

http://blogs.computerworld.com/iphones_safari_browser_to_include_geolocation_0

I confirmed it on my iPhone (it also works in FF3.5).


Sep 29, 2009 at 11:19 AM // reply »
2 Comments

@Ben: you can add also the password type, thus you'll have a password field.


Sep 29, 2009 at 2:42 PM // reply »
1 Comments

More data:

http://ajaxian.com/archives/html5-features-in-latest-iphone-application-cache-and-database

that's usefull thanks


Sep 30, 2009 at 10:24 AM // reply »
9 Comments

Hi Ben,
This might be a silly question, but, do you work with iPhone apps? Or was this just a personal interest because you might have one?


Sep 30, 2009 at 11:13 AM // reply »
7,572 Comments

@Jillian,

Yes, I do work on iPhone applications.


Oct 1, 2009 at 6:23 PM // reply »
1 Comments

Very cool I always like apps that switch the keyboard were it makes since
@Ray the db stuff is way cool. There are some libraries that let you write code that will work in air, safari, google gears and fall back to flash or cookie local storage also. So write once and run on many platforms. Google uses the local storage for Gmail is safari on the iPhone. Check out setting for safari to see what site are using storage.

@Ben you should update the contact form on your blog with the new field types.


Oct 5, 2009 at 4:56 AM // reply »
2 Comments

Really cool !!

So is it possible to have both types password and number ?

Something like :
<input type="password" type="number" name="n1" />

Thanks


Oct 5, 2009 at 7:50 AM // reply »
7,572 Comments

@Drake,

I am not sure about that. I think you can only specify one type at a time.


Oct 5, 2009 at 9:26 AM // reply »
2 Comments

Hi Ben,

Thanks for answering!

I was wondering about that because Dorinake said somehing like that in a previous post, but I can't test it right now. I'll let you know asap if it's possible.


Oct 13, 2009 at 7:21 PM // reply »
1 Comments

I found one more0 type="tel" will give you the alphanumeric keypad!

http://potch.me/iphone


Oct 15, 2009 at 8:23 AM // reply »
7,572 Comments

@Potch,

Ahh, nice!


Nic
Oct 29, 2009 at 1:58 AM // reply »
1 Comments

What generation/firmware version do you need? Your example code doesn't work on mine.


Oct 31, 2009 at 1:57 PM // reply »
7,572 Comments

@Nic,

I'm rocking out version 3.1 (7C144) according to my General settings.


Nov 5, 2009 at 9:15 AM // reply »
2 Comments

Hi, is it possible to change input type in ASP page? I tried to do this in Javascript after page load, but Iphone seems to ignore my change.


Nov 5, 2009 at 9:16 AM // reply »
7,572 Comments

@gorczas,

I am not sure that you can change input types at runtime? I have never tried that.


Nov 6, 2009 at 11:55 AM // reply »
2 Comments

I tried and according to Firebug I succeced, but IPhone didn't notice the change :/


Nov 6, 2009 at 12:04 PM // reply »
7,572 Comments

@Gorczas,

Gotcha. Still, I would try to avoid switching types at runtime.


Nov 14, 2009 at 3:43 PM // reply »
1 Comments

Hi,

first of all thanks for the help from you guys

I have doubt
does file upload works in iphone browser , i found type file as disabled , any method to upload file from a web app


Nov 15, 2009 at 3:38 PM // reply »
2 Comments

Hi guys,

Well, Apple has issued an updated doc for that on 2009-09-24...

Within this doc, you will find all keyboard types, viewport tricks, how to disable auto-correction and auto-capitalization on html fields and more....

http://developer.apple.com/safari/library/codinghowtos/mobile/userexperience/index.html

Hope this helps !

Ps: This works only for iPhone OS 3.1.x and later. ;)

Cheers!


Nov 15, 2009 at 6:51 PM // reply »
7,572 Comments

@Ygor,

Awesome, thanks!


Nov 15, 2009 at 6:59 PM // reply »
7,572 Comments

@Thomas,

I don't think you can upload files since the iPhone doesn't have a file system in the traditional sense.


Dec 18, 2009 at 3:08 AM // reply »
1 Comments

Might try type = tel.... Numbers only no alpha on the keyboard. Worth mentioning that the search type is also available.


Jan 9, 2010 at 7:01 PM // reply »
1 Comments

Great news! I talked to some of the Apple engineers working on mobile Safari at WWDC09 regarding this issue. The response I got was that the old style (setting name attribute to zip, phone etc) was non W3C standard and they had no plans to fix it. I was recommended to file a feature request in Radar. Great that they looked into this. Maybe a lot of developers have complained about this? Thanks for the tips!


Jan 9, 2010 at 9:16 PM // reply »
7,572 Comments

@Marthin,

It's good to know that the engineers are thinking about it. At least it works with the new "type" values.


Jan 14, 2010 at 11:08 PM // reply »
3 Comments

Can anyone else confirm that autofill doesn't work when you use input type="email" or type="number"?

I was beating my head against the screen trying to figure out why autofill skipped certain fields until I switched them back to input type="text" and then autofill worked again.

Seems like a major oversight.


Jan 16, 2010 at 4:25 PM // reply »
7,572 Comments

@Nate,

I am not sure that I know much about the autofill on the iPhone. Are you talking about native browser behavior?


Jan 16, 2010 at 4:37 PM // reply »
3 Comments

Yep, native browser behavior with the latest iPhone OS using Mobile Safari.

If I have a form with zip, email, and phone number fields that all use input type="text", the autofill function works fine with Mobile Safari, all fields are populated with my data.

If I change them to type="number" and type="email" to get those handy keyboard layouts, the autofill doesn't recognize the fields, and therefore leaves them blank.

For a complex checkout form, I'd say usability is better served by keeping them type="text" so autofill works.


Jan 16, 2010 at 4:46 PM // reply »
7,572 Comments

@Nate,

Funky. Yeah, I guess at times when you want to have data autofilled, going with text is gonna be better. I think the only times I would really use this in a practical way would be to use the numeric keyboard to have people enter in numeric line items (which will never be autofilled).


Jan 16, 2010 at 4:57 PM // reply »
3 Comments

I just filed a bug report with Apple. It's the same behavior with normal Safari, see:

http://clixel.com/test_form.html

I agree, for the form in question I ended up using type="number" for credit card and CVV fields, but left the phone, email and zip fields as type="text" for autofill compatibility.


Jan 16, 2010 at 5:21 PM // reply »
7,572 Comments

@Nate,

Yeah, that makes sense - auto-filling CVV fields :)


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 21, 2010 at 8:57 PM
The Bourne Ultimatum Starring Matt Damon And Julia Stiles
late to the party, but my observation is this: rewatch carefully for the platonic nature of the relationship between nicki and jason. she never flirts with him. he never comes on to her. they alway ... read »
Mar 21, 2010 at 7:40 PM
Is Simulating User-Input Events With jQuery Ever A Good Idea?
A couple of things. One you embed the initial state of of more-info in the CSS. IMHO, that behavior should be in jQuery: moreInfo.hide(); It shows that the behavior your toggling and closing is mor ... read »
Mar 21, 2010 at 3:59 PM
Exploring ColdFusion Component Runtime Class Properties And Serialization
@Elliott, according to Ben's experiment, serializeJSON() doesn't access the private data by default - it doesn't even access the getHair() method - so trying to clone a Girl.cfc via serializeJSON/des ... read »
Mar 21, 2010 at 3:49 PM
Ask Ben: Javascript String Replace Method
I'm confused a bit by what you are asking, but if had this sentence: The color, red, is in the style statement; style: red;. and wanted to remove all or change all of the commas, colons, and semi-c ... read »
Mar 21, 2010 at 3:13 PM
Ask Ben: Javascript String Replace Method
I am trying to make a java program to count the number of times that these punctuation marks occur in a body of text: , : ; . ! - ' " ? / \ I am using this piece to ferret out the commas: numcommas ... read »
Mar 21, 2010 at 11:13 AM
A New Wrist Pain
@chiropractor suwanee, Spoken like someone trying to sell something. Other than for minor, temporary relief from some back pain, chiropractic treatment is nothing but placebo effect and quackery. ... read »
Mar 21, 2010 at 6:32 AM
ColdFusion CFPOP - My First Look
Apologies... The field name in the db for C. is "BounceCode" It stores the code / message which is returned in the email. Sorry for the confusion. ... read »
Mar 21, 2010 at 6:29 AM
ColdFusion CFPOP - My First Look
@Jose Galdamez, Hi Ben and Jose 1st of all.. big thanks to Jose for his Skype chat a few weeks back. Your time was much appreciated. I have come up with a rather unelegant solution to my problem a ... read »