Using jquery how can I limit the number of characters that can be typed in a text field? Not referring to a textarea, just a normal text input field. I have a form and viewing v
You need to bind to the keydown event for the field and prevent it from entering a character if there are already 10 in that field: http://jsfiddle.net/j6tJ3/
$('input').keydown(function(e){
if($(this).val().length > 9 && e.which !== 8 && e.which !== 46){ //if it's too long and the key pressed isn't backspace or delete
return false;
}
});