Skip to content

Instantly share code, notes, and snippets.

@nodesocket
Created July 13, 2012 01:49
Show Gist options
  • Save nodesocket/3102236 to your computer and use it in GitHub Desktop.
Save nodesocket/3102236 to your computer and use it in GitHub Desktop.
Textarea MaxLength Enforced
$(document).ready(function() {
$("textarea[maxlength]").bind("keyup input paste", function() {
var limit = parseInt($(this).attr('maxlength'));
var text = $(this).val();
var chars = text.length;
if(chars > limit){
var new_text = text.substr(0, limit);
$(this).val(new_text);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment