Restricted input type for number only by using HTML5
How to make the input type to be valid for number only? We do not need to use javascript, because we can do that easily with 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.
Read: Making an input type for checking valid email address in HTML
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:
Read: Making an input type for checking valid email address in HTML
Good luck.