This plugin allows you to set and limit user input by max characters within html textarea (it is only limited by characters other than words).
It binds keyup, paste and drag events. The extra div is displayed under the textarea, which shows the current number of input characters and words.
You can set your own styles and customise the text counter information. Version 2 provides the callback function.
Notice: For windows OS, new line character occupies two characters (\r\n) instead of one (\n)
Input, drag & drop or paste some texts in the textarea below.
$(document).ready(function(){
var options = {
'originalStyle': 'originalDisplayInfo'
};
$('#testTextarea').textareaCount(options);
});
var options2 = {
'maxCharacterSize': 200,
'originalStyle': 'originalDisplayInfo',
'warningStyle': 'warningDisplayInfo',
'warningNumber': 40,
'displayFormat': '#input Characters | #left Characters Left | #words Words'
};
$('#testTextarea2').textareaCount(options2);
var options3 = {
'maxCharacterSize': 200,
'originalStyle': 'originalDisplayInfo',
'warningStyle': 'warningDisplayInfo',
'warningNumber': 40,
'displayFormat': '#input/#max | #words Words'
};
$('#testTextarea3').textareaCount(options3, function(data){
var result = 'Characters Input: ' + data.input + '
';
result += 'Words Input: ' + data.words + '
';
result += 'Left Characters: ' + data.left + '
';
result += 'Characters Limitation: ' + data.max + '
';
$('#textareaCallBack').html(result);
});
| Options | Description |
|---|---|
| maxCharacterSize | Define the maximum number of characters. Default is -1. Limit characters does work only when maxCharacterSize > 0 |
| originalStyle | Set original class style |
| warningStyle | Set warning class style |
| warningNumber | If number of characters of user input is over the warning number, the information style will be changed to warning style. |
| displayFormat |
Define your display information format. There are four keywords: #input, #max, #left, #words.
For example: 'displayFormat' : '#input characters and #words words' The result will be: 123 characters and 20 words. #input and #words will be substituted by current characters and words Remeber:#max and #left does work only when maxCharacterSize > 0 |
In the 3rd example, you saw that not only counter information was shown but also extra information was displayed in the div above the textarea This is done by the callback function.
$('#testTextarea3').textareaCount(options3, function(data){
var result = 'Characters Input: ' + data.input + '<br />';
result += 'Words Input: ' + data.words + '<br />';
result += 'Left Characters: ' + data.left + '<br />';
result += 'Characters Limitation: ' + data.max + '<br />';
$('#textareaCallBack').html(result);
});
You can pass user defined function as an argument after options.
Function data is an object, which contains four values:
Please read license before you download files from this website.
All file will be wrapped into a .zip file
Please report a bug through jquery plugin site and you need jquery plugin account to login and report.
For any puzzles, concerns and questions about this, please contact me. I will be back to you as soon as possible.