A simple, easy to use and customizable jquery plugin to limit chatacters inside inputs or textareas fields
Download{ limit: 100, // max chars allowed cssClass: '', // css classes to apply on counter separator: '/', // separator of actual and max chars placement: null // jQuery selector of where to append counter Ex: '.counter' }
The basic usage of jQuery Ensure Max Length is discribed bellow.
<script src="path_to_jquery/jquery.min.js"></script> <script src="path_to_plugin/jquery-ensure-max-length.js"></script> <script type="text/javascript"> (function ( $ ) { $( '#example1-title' ).EnsureMaxLength(); } ( jQuery )); </script>
This plugin even works with textareas!
The folowing sample illustrates how to change the default max chars from 100 to 250
<script src="path_to_jquery/jquery.min.js"></script> <script src="path_to_plugin/jquery-ensure-max-length.js"></script> <script type="text/javascript"> (function ( $ ) { $( '#sample2' ).EnsureMaxLength({ limit: 250 }); } ( jQuery )); </script>
jQuery Ensure Max Length allow you to add css class to customize counter.
The classes must be inserted as string separate by a space. class1 class2 class3 ... class3
In this sample we are adding d-block text-right help-block
to counter element.
<script src="path_to_jquery/jquery.min.js"></script> <script src="path_to_plugin/jquery-ensure-max-length.js"></script> <script type="text/javascript"> (function ( $ ) { $( '#sample3' ).EnsureMaxLength({ cssClass: 'class1 class2 class3' }); } ( jQuery )); </script>
You can also changing the separator "/"
to wherever symbol or word you want. In this sample a are changing the "/" to " of ".
<script src="path_to_jquery/jquery.min.js"></script> <script src="path_to_plugin/jquery-ensure-max-length.js"></script> <script type="text/javascript"> (function ( $ ) { $( '#sample4' ).EnsureMaxLength({ separator: ' of ' }); } ( jQuery )); </script>
The use of 'placement' is optional and if you want to use it, you must pass a valid jquery selector to explicit tell to plugin where to append the counter element
Note: If you don't specify a placement this plugin will append the counter element right after the field
<script src="path_to_jquery/jquery.min.js"></script> <script src="path_to_plugin/jquery-ensure-max-length.js"></script> <script type="text/javascript"> (function ( $ ) { $( '#sample5' ).EnsureMaxLength({ placement: '#counter-container' }); } ( jQuery )); </script>