Logo

Bootstrap Maxlength Examples


       <div class="card card-custom">
        <div class="card-header">
         <h3 class="card-title">
          Bootstrap Maxlength Examples
         </h3>
        </div>
        <!--begin::Form-->
        <form class="form">
         <div class="card-body">
          <div class="form-group row">
           <label class="col-form-label text-right col-lg-3 col-sm-12">Default Usage</label>
           <div class="col-lg-4 col-md-9 col-sm-12">
            <input type='text' class="form-control" id="kt_maxlength_1" maxlength="3"  placeholder="" type="text"/>
            <span class="form-text text-muted">The badge will show up by default when the remaining chars are 3 or less</span>
           </div>
          </div>
          <div class="form-group row">
           <label class="col-form-label text-right col-lg-3 col-sm-12">Threshold Demo</label>
           <div class="col-lg-4 col-md-9 col-sm-12">
            <input type='text' class="form-control" id="kt_maxlength_2" maxlength="7"  placeholder="" type="text"/>
            <span class="form-text text-muted">Set threshold value to show there are 5 chars or less</span>
           </div>
          </div>
          <div class="form-group row">
           <label class="col-form-label text-right col-lg-3 col-sm-12">Always Show</label>
           <div class="col-lg-4 col-md-9 col-sm-12">
            <input type='text' class="form-control" id="kt_maxlength_3" maxlength="6"  placeholder="" type="text"/>
            <span class="form-text text-muted">Show the counter on input focus</span>
           </div>
          </div>
          <div class="form-group row">
           <label class="col-form-label text-right col-lg-3 col-sm-12">Custom Text</label>
           <div class="col-lg-4 col-md-9 col-sm-12">
            <input type='text' class="form-control" id="kt_maxlength_4" maxlength="8"  placeholder="" type="text"/>
            <span class="form-text text-muted">Display custom text on input focus</span>
           </div>
          </div>
          <div class="form-group row">
           <label class="col-form-label text-right col-lg-3 col-sm-12">Textarea Example</label>
           <div class="col-lg-4 col-md-9 col-sm-12">
            <textarea class="form-control" id="kt_maxlength_5" maxlength="8"  placeholder="" rows="6"></textarea>
            <span class="form-text text-muted">Bootstrap maxlength supports textarea as well as inputs</span>
           </div>
          </div>
          <div class="form-group row">
           <label class="col-form-label text-right col-lg-3 col-sm-12">Positions</label>
           <div class="col-lg-4 col-md-9 col-sm-12">
            <input type='text' class="form-control" id="kt_maxlength_6_1" maxlength="8"  placeholder="Top left" type="text"/>
            <div class="mt-3"></div>
            <input type='text' class="form-control" id="kt_maxlength_6_2" maxlength="8"  placeholder="Top right" type="text"/>
            <div class="mt-3"></div>
            <input type='text' class="form-control" id="kt_maxlength_6_3" maxlength="8"  placeholder="Bottom left" type="text"/>
            <div class="mt-3"></div>
            <input type='text' class="form-control" id="kt_maxlength_6_4" maxlength="8"  placeholder="Bottom right" type="text"/>
            <span class="form-text text-muted">The field counter can be positioned at the top, bottom, left or right.</span>
           </div>
          </div>
          <div class="form-group row">
           <label class="col-form-label text-right col-lg-3 col-sm-12">Modal Demos</label>
           <div class="col-lg-4 col-md-9 col-sm-12">
            <a href="" class="btn btn-light-primary font-weight-bold" data-toggle="modal" data-target="#kt_maxlength_modal">Launch maxlength inputs on modal</a>
           </div>
          </div>
         </div>
         <div class="card-footer">
          <div class="row">
           <div class="col-lg-9 ml-lg-auto">
            <button type="reset" class="btn btn-primary mr-2">Submit</button>
            <button type="reset" class="btn btn-secondary">Cancel</button>
           </div>
          </div>
         </div>
        </form>
        <!--end::Form-->
       </div>
      

      // Class definition

      var KTBootstrapMaxlength = function () {

       // Private functions
       var demos = function () {
        // minimum setup
        $('#kt_maxlength_1').maxlength({
         warningClass: "label label-warning label-rounded label-inline",
         limitReachedClass: "label label-success label-rounded label-inline"
        });

        // threshold value
        $('#kt_maxlength_2').maxlength({
         threshold: 5,
         warningClass: "label label-warning label-rounded label-inline",
         limitReachedClass: "label label-success label-rounded label-inline"
        });

        // always show
        $('#kt_maxlength_3').maxlength({
         alwaysShow: true,
         threshold: 5,
         warningClass: "label label-danger label-rounded label-inline",
         limitReachedClass: "label label-primary label-rounded label-inline"
        });

        // custom text
        $('#kt_maxlength_4').maxlength({
         threshold: 3,
         warningClass: "label label-danger label-rounded label-inline",
         limitReachedClass: "label label-success label-rounded label-inline",
         separator: ' of ',
         preText: 'You have ',
         postText: ' chars remaining.',
         validate: true
        });

        // textarea example
        $('#kt_maxlength_5').maxlength({
         threshold: 5,
         warningClass: "label label-danger label-rounded label-inline",
         limitReachedClass: "label label-primary label-rounded label-inline"
        });

        // position examples
        $('#kt_maxlength_6_1').maxlength({
         alwaysShow: true,
         threshold: 5,
         placement: 'top-left',
         warningClass: "label label-danger label-rounded label-inline",
         limitReachedClass: "label label-primary label-rounded label-inline"
        });

        $('#kt_maxlength_6_2').maxlength({
         alwaysShow: true,
         threshold: 5,
         placement: 'top-right',
         warningClass: "label label-success label-rounded label-inline",
         limitReachedClass: "label label-primary label-rounded label-inline"
        });

        $('#kt_maxlength_6_3').maxlength({
         alwaysShow: true,
         threshold: 5,
         placement: 'bottom-left',
         warningClass: "label label-warning label-rounded label-inline",
         limitReachedClass: "label label-primary label-rounded label-inline"
        });

        $('#kt_maxlength_6_4').maxlength({
         alwaysShow: true,
         threshold: 5,
         placement: 'bottom-right',
         warningClass: "label label-danger label-rounded label-inline",
         limitReachedClass: "label label-primary label-rounded label-inline"
        });

        // Modal Examples

        // minimum setup
        $('#kt_maxlength_1_modal').maxlength({
         warningClass: "label label-warning label-rounded label-inline",
         limitReachedClass: "label label-success label-rounded label-inline",
         appendToParent: true
        });

        // threshold value
        $('#kt_maxlength_2_modal').maxlength({
         threshold: 5,
         warningClass: "label label-danger label-rounded label-inline",
         limitReachedClass: "label label-success label-rounded label-inline",
         appendToParent: true
        });

        // always show
        // textarea example
        $('#kt_maxlength_5_modal').maxlength({
         threshold: 5,
         warningClass: "label label-danger label-rounded label-inline",
         limitReachedClass: "label label-primary label-rounded label-inline",
         appendToParent: true
        });

        // custom text
        $('#kt_maxlength_4_modal').maxlength({
         threshold: 3,
         warningClass: "label label-danger label-rounded label-inline",
         limitReachedClass: "label label-success label-rounded label-inline",
         appendToParent: true,
         separator: ' of ',
         preText: 'You have ',
         postText: ' chars remaining.',
         validate: true
        });
       }

       return {
        // public functions
        init: function() {
         demos();
        }
       };
      }();

      jQuery(document).ready(function() {
       KTBootstrapMaxlength.init();
      });

      
The badge will show up by default when the remaining chars are 3 or less
Set threshold value to show there are 5 chars or less
Show the counter on input focus
Display custom text on input focus
Bootstrap maxlength supports textarea as well as inputs
The field counter can be positioned at the top, bottom, left or right.

User Profile 12 messages

James Jones
Application Developer
Recent Notifications
Another purpose persuade Due in 2 Days
+28%
Would be to people Due in 2 Days
+50%
-27%
The best product Due in 2 Days
+8%

Shopping Cart

iBlender The best kitchen gadget in 2020
$ 350 for 5
SmartCleaner Smart tool for cooking
$ 650 for 4
CameraMax Professional camera for edge cutting shots
$ 150 for 3
4D Printer Manufactoring unique objects
$ 1450 for 7
MotionWire Perfect animation tool
$ 650 for 7

Select A Demo