I am new to jQuery and little bit confused on how to get only numbers from 1 to 5 in an input box. The following is my code:
HTML
<div id="errmsg"></div>
<input type="text" id="number" maxlength="1"/>
SCRIPT
$(document).ready(function(e) {
$('#number').keydown(function(e){
if (e.which != 8 && e.which != 0 && (e.which < 49 || e.which > 53)) {
//display error message
$("#errmsg").html("Digits Only").show().fadeOut("slow");
return false;
}
else if (e.which == 48 || e.which < 48 || e.which > 53) {
//display error message
$("#errmsg").html("5 Only").show().fadeOut("slow");
return false;
}
})
})
</script>
When the user enters any amount in the input box, if he inputs any character then error message "Digits Only" will be shown. If he enters number more than 5 then error "only 5" message will be shown.