How can I have an input that is limited to 4 numbers/digits, but if text is typed the character length is infinite?
Final working code:
function isNumber (o) {
return ! isNaN (o-0);
}
$("#txt").keyup(function(e){
txtVal = $(this).val();
if(isNumber(txtVal) && txtVal.length>4)
{
$(this).val(txtVal.substring(0,4) )
$(".error").html("4 Numbers Only").show();
return false;
}
});
});