In this article, we learn how to set the legal number intervals in the input field. This helps the user to enter numbers that follow the given interval and disallows any other value during validation.
We have to use the step attribute of the <input> element to set up the legal intervals in the input field. We will first create a form that contains the input area and set its step attribute to the value required. The validation of the field would automatically take place when the user tries to submit the form by showing an error.
<input type="number" step="value">
Example: In this example, the step attribute is set to 4, therefore a user is allowed to enter values that are in steps of 4.