Keegan Teetaert
Keegan Teetaert

Reputation: 673

How to ensure keyboard has the negative key for an HTML number input on mobile devices?

I am developing a mobile application that requires negative numbers to be inputted. However, the mobile keyboard only has the keys [1-9.]. Is there a way to ensure the negative sign is present on the keyboard? I am using the Cordova framework.

Upvotes: 5

Views: 1912

Answers (2)

suyashpatil
suyashpatil

Reputation: 329

If you are still looking for a way to enter - sign using html input tag, try this

<input type="text" inputmode="numeric">

Although, this combination looks weird, it serves the purpose. You will be able to enter - sign in all major devices (including Samsung which otherwise creates problems). You can then parse it to number if you want the user to enter only valid numerics and show validation according to that.

Upvotes: 1

BShaps
BShaps

Reputation: 1414

For cordova the keyboard is determined by the type of input. I believe on most devices using the tel type will have an option for symbols such as a negative sign.

example:

<input type="tel">

If tel doesn't have what you are looking for then you are going to need to put in a text type of input. Either way, the result of a tel type input is a string so you'll need to verify that the input provided is a number.

Note: In the event the device doesn't have a tel type keyboard it will use the normal text keyboard instead.

Upvotes: 1

Related Questions