Allow only all language alphanumeric in jQuery

Viewed 1605

I am trying to make an input that allows all language letters, English, non-English, etc. except special characters, in total:

Allow:

  • All language alphanumeric
  • CTRL / ALT / SHIFT / SPACE / BACKSPACE / SPACE and etc.

Disallow:

  • Special Characters such _-/!@#$%^&*()+=, etc. like emoji and more.

JSFiddle

$('#txtFirstName').on('keydown paste',function(e) {
    if (e.shiftKey || e.ctrlKey || e.altKey) {
        e.preventDefault();
    }
    else {
        var key = e.keyCode;
        if (!((key == 8) || (key == 32) || (key == 46) ||
              (key >= 35 && key <= 40) || (key >= 65 && key <= 90) ||
              (key >= 48 && key <= 57))) {
            e.preventDefault();
        }
    }
});

Well, everything looks great and works fine on desktop, but it is not working on mobile devices like Android or iPhone keyboard, when you use a non-English language keyboard it won't let the user type, so I guess it can't recognize keyboard key code, am I right? Can this issue be fixed? Or can you share another solution for this? Any idea?

1 Answers
Related