$('.last_four').keypress(function() { var string = $(this).text() if ($(this).text().length > 4) return false; });