Skip to content

Instantly share code, notes, and snippets.

@jmleroy
Created May 31, 2017 09:10
Show Gist options
  • Save jmleroy/50974a30820570e18c814db6491bd368 to your computer and use it in GitHub Desktop.
Save jmleroy/50974a30820570e18c814db6491bd368 to your computer and use it in GitHub Desktop.
$("body.refunds.home.rmcuser #idf").on(
"keypress",
function (e) {
var charCode = (typeof e.which == "undefined") ? e.keyCode : e.which;
var charStr = String.fromCharCode(charCode);
return /\d/.test(charStr) // number
|| e.keyCode == 37 || e.keyCode == 39 // left and right arrows
|| e.keyCode == 36 || e.keyCode == 35 // home and end
|| e.keyCode == 8 || e.keyCode == 46 // backspace and delete
|| (e.ctrlKey && (charStr == 'v' || charStr == 'V')); // paste
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment