3

i want to use like this maxlength and minlength both. But it is not working. length of text should be in between 3 to 10 characters

<input type="text" class="form-control" id="username" placeholder="Username" autofocus required maxlength= "10" minlength= "3">

using these maxlength is functioning but minlength not.. but only minlength is working

rdbhandari
  • 71
  • 7
  • https://stackoverflow.com/questions/9555143/html-maxlength-attribute-not-working-on-chrome-and-safari – Pavan Kalyan Dec 17 '20 at 06:12
  • This might be useful: https://stackoverflow.com/questions/10281962/is-there-a-minlength-validation-attribute-in-html5 – Harshana Dec 17 '20 at 06:16
  • Here is the solution https://stackoverflow.com/questions/9841363/how-to-restrict-number-of-characters-that-can-be-entered-in-html5-number-input-f – Avinash Rathod Dec 17 '20 at 06:33

4 Answers4

2

There is an alternative way of doing it in HTML, here it is

<form>
  <label for="name">Name:</label>
  <input type="text" name="name" required minlength="3" maxlength="10" size="10">

  <button type="submit">Submit</button>
</form>
1

You can also validate the character length with pattern attribute like this:

<form>
  <label for="username">Userame:</label>
<input name="username" pattern=".{3,10}" required title="3 to 10 characters">
<button type="submit">Submit</button>
</form>
Ajay Choudhary
  • 271
  • 3
  • 16
0
<html>
<body>

<h1>The input maxlength attribute</h1>

<form action="/action_page.php">
  <label for="username">Username:</label>
  <input type="text" id="username" name="username" maxlength="10" minlength="5"><br><br>
  <input type="submit" value="Submit">
</form>

</body>
</html>
0

You can use this one, I have checked and this works.

<form>
   <label for="username">Userame:</label>
   <input type="text" name="txtName" minlength="3" maxlength="10" required>
   <button type="submit">Submit</button>
</form>
Jinesh Gandhi
  • 67
  • 1
  • 11