I do not want users to enter numbers or special character within a name input field and I have achieved this with the following code:
jQuery(document).ready(function() {
jQuery(".txtOnly").keypress(function(e) {
var key = e.keyCode;
if(key < 97 || key > 122) {
e.preventDefault();
}
});
});
But I want to avoid numbers and special characters from microsoft IME Japanese Keyboard as well though the keypress does not work so I am using a jQuery composition event which is working but it always returns undefined, so I am unable to get the key code or the value this way.
My Code:
jQuery(document).ready(function() {
jQuery(".txtOnly").on('compositionupdate', function(e) {
var keyCode = e.keyCode;
alert(keyCode); //Undefined
console.log(e.data); //Undefined
});
});
How I can get the keycode using a composition event or what other solution can I use for the Microsoft IME Japanese Keyboard?