Skip to content

Instantly share code, notes, and snippets.

@ariona
Created September 10, 2018 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariona/55efa2ca482e5f9d4c8e29faac5f451a to your computer and use it in GitHub Desktop.
Save ariona/55efa2ca482e5f9d4c8e29faac5f451a to your computer and use it in GitHub Desktop.
function isCharacterKeyPress(evt) {
if (typeof evt.which == "undefined") {
// This is IE, which only fires keypress events for printable keys
return true;
} else if (typeof evt.which == "number" && evt.which > 0) {
// In other browsers except old versions of WebKit, evt.which is
// only greater than zero if the keypress is a printable key.
// We need to filter out backspace and ctrl/alt/meta key combinations
return !evt.ctrlKey && !evt.metaKey && !evt.altKey && evt.which != 8;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment