How to identify what keyboard language is with jquery

I have used two different approaches for detecting English and Persian characters in my solution:

document.getElementById('a').addEventListener('keypress',function(e){
     if (isEnglish(e.charCode))
       console.log('English');
     else if(isPersian(e.key))
       console.log('Persian');
     else
       console.log('Others')
});

function isEnglish(charCode){
   return (charCode >= 97 && charCode <= 122) 
          || (charCode>=65 && charCode<=90);
}

function isPersian(key){
    var p = /^[\u0600-\u06FF\s]+$/;    
    return p.test(key) && key!=' ';
}
<input id="a" type="text"/>


I don't think that's possible - anyway it's probably not what you want (Caps Lock, for example, will still output English) I'd recommend placing a keypress event listener on your textarea and checking each letter against a "Persian only" regex like this (untested):

document.getElementById('a').addEventListener('keypress',function(e){
     if (e.charCode > 160) 
     console.log('persian');
     else
     console.log('english');
});
<input type="text" id="a"/>