Skip to content

Instantly share code, notes, and snippets.

@Macagare
Created December 20, 2012 09:20
Show Gist options
  • Save Macagare/4344082 to your computer and use it in GitHub Desktop.
Save Macagare/4344082 to your computer and use it in GitHub Desktop.
Javascript: check Textarea max length
$("textarea[maxlength]").keydown( function(e) {
var key = e.which; // backspace = 8, delete = 46, arrows = 37,38,39,40
if ( ( key >= 37 && key <= 40 ) || key == 8 || key == 46 ) return;
return $(this).val().length < $(this).attr( "maxlength" );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment