limit max length - Free Download Limit The Amount Of Characters Within Input/Textarea - maxLength

Free Download Limit The Amount Of Characters Within Input/Textarea – maxLength

Posted on

This time I will share jQuery Plugin and tutorial about Limit The Amount Of Characters Within Input/Textarea – maxLength, hope it will help you in programming stack.

limit max length - Free Download Limit The Amount Of Characters Within Input/Textarea - maxLength
File Size: 5.35 KB
Views Total: 490
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

maxLength is a tiny (~2kb minified) jQuery plugin that limits characters for an input or textarea element using the native maxlength attribute and displays a counter indicating how many characters are remaining.

More Features:

  • The character counter is displayed only when you are typing.
  • Automatically prevents typing when you reach the max limit.
  • Supports paste event.

How to use it:

1. Determine the maximum character limit for your input or textarea element using the maxlength attribute:

1 <h2>Input</h2>
2 <input maxlength="56" />
3 <h2>Textarea</h2>
4 <textarea maxlength="140"></textarea>

2. Download the plugin and insert the JavaScript jquery-maxlength.min.js after loading jQuery library.

1 <script src="/path/to/cdn/jquery.min.js"></script>
2 <script src="/path/to/jquery-maxlength.min.js"></script>

3. Attach the plugin to the input and/or textarea element and done.

1 $(function(){
2   $("input,textarea").maxlength({
3     // options here
4   });
5 });

4. Customize the appearance of the character counter.

  • text: text to display in the counter
  • position: “left” or “right”
  • color: font color
  • fontSize: font size
  • template: container element
  • showTemplate: whether to show the template
1 $("input,textarea").maxlength({
2   text: "{total}/{maxLength}",
3   position: "left",
4   color: "grey",
5   fontSize: "12px",
6   template: "<div />",
7   showTemplate: true
8 });

This awesome jQuery plugin is developed by GururajNadager. For more Advanced Usages, please check the demo page or visit the official website.