0

I have an input field:

<input name="onkirmizi[]" type="text" class="form-control" tabindex="1" >

And I want to give this input field validation which only allows 2 characters allowed. So in this point, I have two questions.

  1. Do I need to put it inside of the form?
  2. Do I need to add js file (if so how can I do that)?
magic bean
  • 787
  • 12
  • 39

1 Answers1

3

Attribute maxlength

Accepts a positive integer

When this number is reached during dialing, no further input is possible.

<!DOCTYPE HTML>
<html>
 <head>
  <meta charset="utf-8">
  <title>Tag INPUT, attr maxlength</title>
 </head>
 <body>

  <form  action="handler.php">
   <p><input type="text" maxlength="2"></p>
   <p><input type="submit" name="submit" value="Submit"></p>
  </form> 

 </body>
</html>
Ulanbek
  • 42
  • 3
  • 1
    Welcome to Stack Overflow. Code without any explanation are rarely helpful. Stack Overflow is about learning, not providing snippets to blindly copy and paste. Please edit your question and explain how it answers the specific question being asked. See [How to Answer](https://stackoverflow.com/help/how-to-answer). – Sfili_81 Nov 17 '21 at 08:23