In addition to min
and max
, HTML5 gives you the step
attribute. For example, <input type="number" min="1" max="50" step="10">
gives you acceptable values of 1, 11, 21, 31, and 41. Beyond those three attributes, there is JavaScript.
If you really do not want to use JavaScript, then you can try to use a regular expression with the pattern
attribute of the input
element. Note that the pattern attribute requires that your input type be set to text
instead of to number
and include a title
that is used to describe the pattern. Also note that regular expressions are meant for parsing text character by character, which makes it difficult to deal with numbers beyond a single digit.
Here's an example that allows 1-40, 45, and 50 (but not if the number is preceded by a zero):
<input type="text" name="example-number"
pattern="(^40$)|(^45$)|(^50$)|(^1[0-9]$)|(^2[0-9]$)|(^3[0-9]$)|(^[1-9]$)"
title="A number in the range of 1-40, 45, or 50">
Plenty of people recommend using code (e.g., JavaScript) instead of a regular expression for validating numeric ranges, which may be why an entire site dedicated to input patterns does not have any listed for numeric ranges.