Restricted input type for number only by using HTML5
Let say we want to make an input type for temperature with the following rule: minimum 30o and maximum 50o, but allowing to input one decimal digit.
The example is 30.1o.
To do that we can make HTML code like below:
<input id="temperature" class="form-control" max="50" maxlength="4" min="30" name="temperature" size="50" step="0.1" type="number" />
type="number" is used to make the input type is valid for number only.
step="0.1" is used when clicking on up/down button.
min="30" max="50" is the minimum and maximum number so the form can be submitted.
The result of the example above is like below: