Brad Frost

Better Numerical Inputs for Mobile Forms

usable numeric inputs in iOSMy colleagues in Chicago just launched a great responsively-designed greygoose.com, and Jason Grigsby and I were wondering how they brought up the user-friendlier telephone keypad in iOS instead of the ok-but-not-great number keypad. The team dynamically set the input type to tel with Javascript, but we were wondering if there would be a better way. After some Twitter-talk with Grigsby and Chris Coyier, I set up a demo page to see if setting pattern="[0-9]* would make a difference. Thankfully it did. So here's the recommended format for numeric input types:

Adding pattern="[0-9]*" triggers iOS to bring up the obese-finger-friendly keypad instead of the just-alright numeric keypad riddled with punctuation. Usability wins and the crowd goes wild. By default iOS only triggers the number-only keypad on tel inputs, but this way the input type and the keypad don't need to be bound. Semantics win and the crowd rises to their feet in jubilation. Also worth noting the Kindle Fire pulls up a friendlier keypad regardless of whether pattern="[0-9]* is set: [caption id="attachment_2678" align="alignnone" width="650" caption="Number & Tel inputs on Amazon Kindle"]Number & Tel inputs on Amazon Kindle[/caption] Big thanks to Björn Rixman, Chris and Jason for working through this! Related Resources:

Update There are a few things that people pointed out in the comments or in other posts regarding numeric input types:

Some fine people have written about these issues in more detail: