Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make input field type both numeric and password? [duplicate]

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">
like image 980
kaleazy Avatar asked Jan 15 '12 17:01

kaleazy


People also ask

How do you make an input field a password?

To take password input in HTML form, use the <input> tag with type attribute as a password.

Which input types use for password field?

The <input type="password"> defines a password field (characters are masked).

Which attribute can be used in a password field to limit the number of characters that can be entered in a field?

The maxlength attribute defines the maximum number of characters (as UTF-16 code units) the user can enter into an <input> or <textarea> . This must be an integer value 0 or higher.


3 Answers

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".

like image 60
marco Avatar answered Sep 21 '22 18:09

marco


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.

like image 37
Tono Nam Avatar answered Sep 22 '22 18:09

Tono Nam


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

like image 36
Alex Datcu Avatar answered Sep 22 '22 18:09

Alex Datcu