Created
July 13, 2012 01:49
-
-
Save nodesocket/3102236 to your computer and use it in GitHub Desktop.
Textarea MaxLength Enforced
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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