I\'ve got four inputs that each take one number. What I want to do is set the focus automatically to the next input once the number has been set. They all have the class \"i
This is the code that complete your all needs.
$(".input").keyup(function(e) {
if (e.which == 8 || e.which == 46){
//backspace / Delete
$(this).val('');
$(this).prevAll('input:first').focus();
}
else
{
var spcl_arr = ["~","!","@", "#", "$", "%", "^", "&", "*", "(", ")", "+","-", "=", "." ,"/"];
if(e.which == 13){ // Enter Kay
return false;
}
else if(jQuery.inArray($(this).val(), spcl_arr) !== -1 ){
$(this).val('');
$(this).focus();
return false;
}else{
var regex = new RegExp("^[a-zA-Z0-9]+$");
var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
if (regex.test(str)) {
if (this.value.length == this.maxLength) {
$(this).next('.input').focus();
}
}else{
$(this).val('');
$(this).focus();
return false;
}
}
}
});