EN
HTML - set text input min length
0
points
In this article, we would like to show you how to set text input element min length in HTML.
Quick solution:
<input type="text" name="username" minlength="5" />
Note:
The
inputwill fail constraint validation onformsubmit if the length of the text entered into the field is fewer thanminlength.
Practical example
In this example, we use input element's minlength attribute to set the minimum number of input element characters.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<body>
<form>
<label>
<span>Username (min 10 characters):</span>
<input type="text" name="username" minlength="5" />
</label>
</form>
</body>
</html>