How to limit the number of characters allowed in the form input text field with HTML?

Spread the love

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.

Leave a Reply

Your email address will not be published. Required fields are marked *