0

<input type="text"> brings up this keyboard:

text keyboard

while <input type="number"> brings up this one:

numerical/secondary keyboard

Is there a way to keep the input type text and invoke the second keyboard? perhaps with a pattern attribute?

My issue with input type="number" is that the user is expected to input fractions and $("#input_id").val(); is having trouble with space and forward slash, e.g 3 5/6 returns 3 and 7/13 returns 7.

if this can be bypassed i can also work with that.

banana1
  • 545
  • 1
  • 4
  • 16

1 Answers1

-1

<input type="text"> will always invoke primary keyboard.

What you can do is:

  • Prevent user from typing any character other than 0-9 and .(dot) by checking keycode or by regular expression
    eg: [0-9][.][0-9]{1-2} returns true for one or two decimal places.
  • Add some validation rule to the input field and show error when user submits the form
Community
  • 1
  • 1
Avijit
  • 1,253
  • 13
  • 21
  • I am not worried about input validation but ease of use. I don't want the user to have to switch keyboards even once, let alone every character. – banana1 Apr 17 '16 at 10:55
  • Why don't you use `` to invoke secondary keyboard directly and then prevent input of those special characters. – Avijit Apr 17 '16 at 12:22
  • My issue with input type="number" is that the user is expected to input fractions and $("#input_id").val(); is having trouble with space and forward slash, e.g 3 5/6 returns 3 and 7/13 returns 7 – banana1 Jun 01 '16 at 09:08