3

I have a simple webform targeted for Opera Mini and Opera Mobile. I'm using just a HTML input element.

Now I would like to restrict the element to only have integer numbers. Is there a way to enforce this in this browser (possible even that the phone will have it's number mode on when entering the form)?

And if I wanted to allow floats, is something possible then?

Peter Smit
  • 27,696
  • 33
  • 111
  • 170

3 Answers3

1
<input type='tel' /> 

will bring up a numeric keypad on Android, WP8, and iPhone default browsers as well as Chrome for Android. On my Android browsers, non-numeric characters are stripped onblur.

<input type='number' /> 

should work fine for floats. On both of my Android browsers, it also automatically removes leading zeros onblur.

Ivy
  • 887
  • 1
  • 7
  • 25
  • Neither work in Opera Mini. It seems like they don't support this part of HTML5 yet. I went with `tel` since it's most widely supported by other mobile browsers. – Magne Nov 19 '13 at 21:35
  • The keyboard behavior is up to the browser and which modes the device's keyboard exposes. As far as I know, these HTML5 input types are the only way to suggest which keyboard mode you want. If Opera Mini doesn't recognize them, I don't think there's any way you can force a keyboard (short of making your own javascript on-screen-keyboard for this site). Sorry. – Ivy Nov 20 '13 at 15:35
  • I know. =/ Do you know of any good javascript on-screen-keyboards which could only activate for Opera Mini, and replace their default? – Magne Nov 21 '13 at 14:16
  • I haven't used any, but I found this just now on SO: http://stackoverflow.com/questions/8762431/js-based-on-screen-keyboard-for-browser-like-on-cellphones-and-tablets – Ivy Nov 21 '13 at 18:40
1

You should be able to use the "number" input type, it's part of the HTML5 spec. I'm unsure if Opera will automatically display the numeric keypad but the iphone at least does...

dsas
  • 1,650
  • 18
  • 30
1

In XHTML Basic, you can use inputmode="digits" on your <input> tags to accomplish this. It ought to be more widely supported on mobile browsers that HTML5 mechanisms.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173