Sometimes, we want to limit the number of characters allowed in the form input text field with HTML.
In this article, we’ll look at how to limit the number of characters allowed in the form input text field with HTML.
How to limit the number of characters allowed in the form input text field with HTML?
To limit the number of characters allowed in the form input text field with HTML, we set the maxlength
attribute.
For instance, we write
<input type="text" id="sessionNo" name="sessionNum" maxlength="5" />
to set the maxlength
attribute to 5 to validate that the input value has max length of 5 characters.
Conclusion
To limit the number of characters allowed in the form input text field with HTML, we set the maxlength
attribute.