Monty_Can
Monty_Can

Reputation: 147

Can't set few numbers into <input type="number">

I am trying to set few numbers into <input type="number"> like 22,33,44, but after submited my form, the value into my input tag is "", if I set only two numbers it works like "22.33", but with 3 numbers validation is not pass. How can I set 3 numbers or more and pass the validation?

Upvotes: 0

Views: 715

Answers (4)

shilch
shilch

Reputation: 1935

Use <input type="text" pattern="(\d+)(,\s*\d+)*" /> instead.

Upvotes: 1

Bkjain655
Bkjain655

Reputation: 200

You need to use type text and perform the validations using regex or string manipulation. input type = number is used to set only single value like 22 or 33 or 44 but not combination i.e. "22,33,44".

Upvotes: 0

Stevik
Stevik

Reputation: 1152

Into <input type="number"> you can inser only a number, "22.33" is still a signle number, but it's decimal, not an intere which is correct.

If you want to insert multiple numbers separated by comma (,) you have to use <input type="text"> and then parse the content of the input.

Upvotes: 0

josh_boaz
josh_boaz

Reputation: 2023

the issue is the commas ',' you have. Input type 'number' only takes in numbers, it is invalid with commas, remove comma and it should work

Upvotes: 0

Related Questions