-
-
Save cpilsworth/5150617 to your computer and use it in GitHub Desktop.
Listen for textarea changes to textarea and limit length according to maxlength attribute
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).on('keyup input paste', 'textarea[maxlength]', 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