Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone Development - How to display a numeric keyboard?

I'm working on a mobile website which is NOT a native iPhone app but rather a simple m.somedomain.com website which is developed in c# asp.net .

Objective : On clicking one of the text boxes how do I display the numeric keyboard only ?

Note : The website is NOT in HTML5 and is not part of a webview inside a Native app but rather a standalone regular website

My textbox is a regular asp.net text box :

<asp:TextBox runat="server" CssClass="reference_input" Text="1234567"  />
like image 455
Murtaza Mandvi Avatar asked Jul 19 '11 20:07

Murtaza Mandvi


2 Answers

EDIT: I found here that you can use

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

to tell mobile safari to set the numeric keyboard as default, without needing to specify the telephone keyboard.

EDIT 2 (from comments below): You can also use javascript to force numeric input as so:

<input type="text" pattern="[0-9]*" onKeypress="if(event.keyCode < 48 || event.keyCode > 57){return false;}" />

like image 133
mopsled Avatar answered Oct 18 '22 17:10

mopsled


If you use type="tel" instead of type="text" it will bring up a numeric keyboard.

like image 20
Nick Avatar answered Oct 18 '22 17:10

Nick