Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

weird bug but on javascript onkeydown

i have this script working but it allows letters and disallows numbers along the top of the keyboard but for some reason it allows the number pad. how do i make it so it only allows lower case letters?

function isAlphaKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode;
     if ((charCode==231 || charCode==199) || (charCode==241 || charCode==209) ||(charCode==8 || charCode==32) || ( (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) ) ) {
        return true;
     }
     else {
         return false;
     }
} 
like image 493
Jonny Avatar asked Feb 14 '26 01:02

Jonny


1 Answers

Modified code, allowing only 231, 199, 241, 209, 8, 32 and lower case characters

var allowedNumber = [231, 199, 241, 209, 8, 32];
function isAlphaKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode;
     if ( allowedNumber.indexOf(charCode) != -1 || ( charCode >= 97 && charCode <= 122) ) {
        return true;
     }
     else {
         return false;
     }
} 
like image 62
Anoop Avatar answered Feb 16 '26 14:02

Anoop



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!