I'm using regex to only allow letters, numbers and dot (.)
$('input').on('keydown', function (e) {
if (/^[a-zA-Z0-9\.\b]+$/.test(String.fromCharCode(e.keyCode))) {
return;
} else {
e.preventDefault();
}
});
However, one can still insert characters like ", é, ~e, #, $, etc. So i mean characters you type with the Shift key.
Also, typing characters using alt+1234 for example are still allowed.
Is there a way to prevent this on the keydown event of an input?