You cannot stop a keystroke even from keydown ... they are both separate events. What you can do is cancel keydown / keypress after reading the character. Here I am making sure that only letters and numbers are entered in the text box (jQuery)
urlBox.keypress(function(e){
if(e.which == 13 || e.which == 8 || e.which == 0) return true;
if(48 <= e.which && e.which <= 57) return true;
if(65 <= e.which && e.which <= 90) return true;
if(97 <= e.which && e.which <= 122) return true;
return false;
});
source
share