watkib
watkib

Reputation: 347

Validating input type number in html5

I want to restrict entry of input onto a field of type number such that input cannot be outside range of min-max specified in the html.

input type = "number" min = "1" max = "5"

Is there a way of outputting the number field without the text box and i would rather not use

"input type = range"

as slider does not show value currently selected

Please help.

Thanks.

Upvotes: 0

Views: 9154

Answers (2)

Rex Adrivan
Rex Adrivan

Reputation: 1009

<form>
  Only 1 to 100 <input type="text" name="number" pattern="\d{1,2}(?!\d)|100" title="one to hundreed only">
  <input type="submit">
</form>

Upvotes: 0

Ian Devlin
Ian Devlin

Reputation: 18870

Based on what you said, I suggest using a simple input text field and check it's value validity on submission via JavaScript (as @Kush mentions above). You could also check it as the user types, or moves focus away from that field.

Upvotes: 3

Related Questions