Languages
[Edit]
EN

HTML - set text input min length

0 points
Created by:
Inayah-Alexander
767

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

Alternative titles

  1. HTML - set text input minimum length
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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