22

I'm aware of this:

<input type="tel">

and I'm aware of this:

<input type="password">

But I would like to use both. I want the numeric keypad to come up on iOS (specifically) but hide each character after it's typed. Is something like this possible?

<input type="tel|password">
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
kaleazy
  • 5,922
  • 2
  • 47
  • 51

3 Answers3

16

For iOS you can set the input to type "password" and still trigger the numeric-keyboard using the HTML5-Attribute "pattern":

<input type="password" pattern="[0-9]*" ... />

From the Apple-Documentation:

To display a numeric keyboard, set the value of the pattern attribute to "[0-9]" or "\d".

marco
  • 239
  • 2
  • 4
8

Html of input box:

<input type="tel" name="password" id="password" value="" placeholder="Enter password"
    onfocus="changeToPassword()">

Javascript:

// change the type of the input to password
function changeToPassword() {
    setTimeout(function () {
        document.getElementById("password").setAttribute("type", "password")
    }, 500);
}

this solution works on the iphone. This is kind of a hack. Once you have the number pad in the next 500 miliseconds you change the attribut to password and that tricks the phone.

Tono Nam
  • 34,064
  • 78
  • 298
  • 470
  • 4
    This wont work again. After someone enters the information and blurs out and tries to re enter the information, now the type is already set to password, number keypad wont come. – Fyre Oct 14 '14 at 03:55
1

You can make the input type password and then use javascript to validate that only numbers have been entered when the submit button has been pressed. http://www.configure-all.com/javascript_form_validation.php

Alex Datcu
  • 53
  • 1
  • 2
  • 5
  • 1
    This would've been my answer too, but it seems that the OP wants to enable some iOS-specific UI features that are normally triggered by `type="tel"`. I don't think JS input validation will help with that. – Ilmari Karonen Jan 15 '12 at 21:55
  • Answer link is no longer valid. What would be an updated link to help? – Whitecat Oct 24 '17 at 18:28