1

Would like a HTML number field where the user can enter numbers separated by commas and spaces... like '1, 2, 3.' Right now it only accepts inputs without commas and spaces and won't let me submit the form with commas/spaces in the field.

Here's a sample of my simple input field now: <input id="A" name="HLA-A" type="number" />

Need number field so number keyboard will pop up on smart phones.

Did a good bit of looking and I'm surprised I didn't find anything on this... perhaps there is a simple answer? Anyone have any ideas?

Thanks!

Tee
  • 57
  • 1
  • 9
  • 1
    You will need to use `type="text"` and do the logic yourself. You may use `pattern="\d+,\d+,\d+"` – w35l3y Aug 02 '15 at 23:59
  • I really couldn't find a solution. On my iPhone any pattern using \d doesn't bring up the number keyboard automatically. I can't use a pattern anyway because the input must be flexible, sometimes users will not have multiple numbers... I tried most everything on this thread concerning number html input [here](http://stackoverflow.com/questions/6178556/iphone-numeric-keyboard-for-text-input), but nothing worked for the specific format I want. Just will use text field for now. Any more advice appreciated! Thanks for your previous suggestions too. – Tee Aug 03 '15 at 14:51

1 Answers1

1

If you REALLY need type="number", then you should do as follows:

<input type="number" />,<input type="number" />,<input type="number" />

Otherwise, you could do as follows:

<input type="text" pattern="\d+, \d+, \d+" />

Both ways, some browsers may not support it.

w35l3y
  • 8,613
  • 3
  • 39
  • 51
  • I really do need to use number unfortunately. Obviously I'm somewhat new to html... but wouldn't your first suggestion just create three separate fields? – Tee Aug 03 '15 at 01:39
  • Liking the text pattern though.. I would definitely use that if the number keyboard still popped up on phones for that field. No other way for that to happen then to have a number type field that I know of. I'll google. – Tee Aug 03 '15 at 01:42
  • Is there an advantage to use `\d+` instead of `[0-9]+`? – VeryColdAir Oct 10 '22 at 15:08
  • 1
    There isn't any difference. It is up to you decide which one to use, @VeryColdAir – w35l3y Oct 10 '22 at 16:26