Languages
[Edit]
EN

HTML - set text input min length

0 points
Created by:
Inayah-Alexander
437

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 input will fail constraint validation on form submit if the length of the text entered into the field is fewer than minlength.

 

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>

References

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join