How to force input to only allow Alpha Letters?
Short ONELINER:
<input onkeydown="return /[a-z]/i.test(event.key)" >
For all unicode letters try this regexp: /\p{L}/u
(but ... this) - and here is working example :)
The property event.key
gave me an undefined value. Instead, I used event.keyCode
:
function alphaOnly(event) {
var key = event.keyCode;
return ((key >= 65 && key <= 90) || key == 8);
};
Note that the value of 8 is for the backspace key.