Skip to content

Instantly share code, notes, and snippets.

@daveespionage
Created September 25, 2012 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveespionage/3782495 to your computer and use it in GitHub Desktop.
Save daveespionage/3782495 to your computer and use it in GitHub Desktop.
Super simple Character Limit checker in Javascript
// Check character count and limit input field
// -------------------------------------------
// Original from: http://www.9lessons.info/2010/04/live-character-count-meter-with-jquery.html
//
$("#tweetBox").on('keyup',function()
{
var box=$(this).val();
var limit= 140
var count= limit - box.length;
if(count >= 0)
{
$('#count').html(count);
}
else
{
// truncate
$(this).val(box.substring(0,limit));
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment