I have a credit card number input form that will be used by both mobile and non-mobile browsers.
I want to hint that a keypad should appear on mobile, and to allow (optional) spaces, so either "4111 1234 1234 1234" or "4111123412341234" should be accepted.
From what I've found, the options are:
a) <input type="tel"/>
- this seems to behave as I want (with current mobile browsers at least), but it's semantically wrong.
b) <input type="text" pattern="[\d ]*"/>
or similar - the iPhone recognises some patterns ([0-9]*
, \d*
) as working with the keyboard, but this doesn't work as well on Android. Also I'm not sure there are any patterns that the iPhone will give a numpad for that allow spaces, though I don't have an iPhone on hand to check right now.
c) Attempt browser detection with Javascript and use (a) for mobile and (b) for non-mobile. Cludgy, and no real benefit over (a).
<input type="number"/>
seems to be a non-starter since Chrome at least will force such input to a number, therefore breaking input with spaces.
Is there a better way of hinting to mobile browsers that they should offer a numpad than using type="tel"
?
Edit:
Maybe a -webkit-*
property that could be applied to a normal text input field to hint that a numpad should be shown?