I am trying to filter user input by using a custom jQuery function :
$(document).ready(function(){
$('#afm').keypress(function(key){
var len = $('#afm').val().length;
console.log(key.charCode);
if( key.charCode < 8 || (key.charCode > 8 && key.charCode < 48) || key.charCode > 57 && len < 9){
$('#tip-afm').text("error");
return false;
}
else
$('#tip-afm').text("");
})
})
Whenever i press backspace, console.log displays charCode as 0. As far as i know 8 is code assigned to backspace.. Am i doing something wrong? Do i have to change the code to handle backspace's code as 0?Or this may lead to errors in the future?