gstRegVal.bindSizeLimiter = function(selector, maxLength) { $(selector).bind('keyup keydown paste', function(e) { var textValue = $(this).val(); if (textValue.length >= maxLength && (e.which != undefined && (e.which >= 48 || e.which==13))) { // NB: the user is allowed to press delete key, up arrows, etc (ie. char codes less than 48 are allowed) // but the user is NOT allowed to press the return key (char code 13) return false; }; }); }