Jquery validation min and max length

Min length method:

Description: Makes the element require a given minimum length.

Return false if the element is

  • some kind of text input and its value is too short
  • a set of checkboxes that doesn’t have enough boxes checked
  • a select and doesn’t have enough options selected

Works with text inputs, selects and checkboxes.

Makes “field” required having at least 3 characters.

<!doctype html>
<meta charset="utf-8"> 
<title>Makes "field" required having at least 3 characters.</title> 

<link rel="stylesheet" href="https://jqueryvalidation.org/files/demo/site-demos.css"> 
<form id="myform">
    <label for="field">Required, minimum length 3: </label> 
    <input type="text" class="left" id="field" name="field"> 
    <input type="submit" value="Validate!"> 
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script> 
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>
// just for the demos, avoids form submit 

    debug: true, 
    success: "valid" 

$( "#myform" ).validate({ 
    rules: { 
       field: { 
          required: true, 
          minlength: 3 

Leave a Comment