with JQuery,
$("input").keypress( function(e) {
var chr = String.fromCharCode(e.which);
if ("12345NOABC".indexOf(chr) < 0)
return false;
});
without JQuery
document.getElementById("foo").onkeypress = function(e) {
var chr = String.fromCharCode(e.which);
if ("12345NOABC".indexOf(chr) < 0)
return false;
};
For one liners, from @mplungjan and @matthew-lock’s comment
document.querySelector("#foo").onkeypress = function(e) {
return "12345NOABC".indexOf(String.fromCharCode(e.which)) >= 0;
};