AJAX
Basics
Data
DOM
Effects
Events
Forms
jQuery UI
Plug Ins
Traversing
The jQuery event.which will return which keyboard key was pressed.
Type a character in the textbox. Watch what happens when you press the key; hold the key down, and the release the key.
There are a few events to keep in mind when you are trying to detect and validate input which are:
http://www.w3schools.com/jquery/event_which.asp
http://api.jquery.com/keydown/
http://api.jquery.com/keypress/
$(document).ready(function ()
{
$("#txtDemo").keydown(function (event)
{
console.dir(event);
$("#demo1").html("Key: " + event.which + " was pressed down.");
});
$("#txtDemo").keyup(function (event)
{
console.dir(event);
$("#demo2").html("Key: " + event.which + " was released.");
});
});