Try the solution below if you consider it in multiple text boxes.
$(function() { var charLimit = 4; $(".inputs").keydown(function(e) { var keys = [8, 9, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145]; if (e.which == 8 && this.value.length == 0) { $(this).prev('.inputs').focus(); } else if ($.inArray(e.which, keys) >= 0) { return true; } else if (this.value.length >= charLimit) { $(this).next('.inputs').focus(); return false; } else if (e.shiftKey || e.which <= 48 || e.which >= 58) { return false; } }).keyup (function () { if (this.value.length >= charLimit) { $(this).next('.inputs').focus(); return false; } }); });
It has the following functions,
- Autotabs for next input
- Numeric only
- charLimit - setting different lengths
DEMO: http://jsfiddle.net/skram/qygB2/20/
source share