In your callback, you can check the keyCode event keyCode . If you want to block key entry, just return false . For instance:
$('#element').keypress(function(e) { if(e.which < 65 || e.which > 90)
Please note that this will not work very well. The user can still insert other text or use a mouse-based input device or any other.
I edited this based on Tim Down's comment and replaced keyCode with which , which is true for keydown , keyup and keypress .
source share