Skip to content

Instantly share code, notes, and snippets.

@danwoods
Created September 24, 2012 17:55
Show Gist options
  • Save danwoods/3777297 to your computer and use it in GitHub Desktop.
Save danwoods/3777297 to your computer and use it in GitHub Desktop.
Restrict the number of characters in an input/textarea
// onkeyup="restrictchars(this, someInteger)"
var restrictChars = function(elm, maxLen){
var len = elm.value.length;
if(len >= maxLen){
elm.value = elm.value.substring(0, maxLen);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment