You can find the length of the value using the jQuery val () method, which returns the current value of the form element as a string. Then you can use the length property from this line.
$('input').on('keyup',function(){ alert('This length is ' + $(this).val().length); });
Here is a working jsFiddle example: http://jsfiddle.net/J58ht/
on your edited question it should be like
$('input').on('keyup',function(){ var my_txt = $(this).val(); var len = my_txt.length; if(len > my_constant_length) { var res = my_txt.substring(1,my_constant_length); $(this).val(res); } });
source share