jquery - input textbox validations based on unicode -


i have applied validations on input textbox using keycode. how can using unicode. in code shown below, have restricted special characters in textbox seen using keycode want restrict using unicode.

$('.alphaonly').keydown(function (e) {     var pressedkey = e.keycode;     if ($(this).getcursorposition() == 1 || $(this).getcursorposition() == 0) {         if (pressedkey == 32) {             e.preventdefault();          }     }     if (!((pressedkey == 8) || (pressedkey == 9) || (pressedkey == 32) || (pressedkey == 46) || (pressedkey >= 35 && pressedkey <= 40) || (pressedkey == 17) || (pressedkey == 18) || (pressedkey == 19) || (pressedkey >= 65 && pressedkey <= 90))) {         e.preventdefault();     }  }); 

use e.charcode (which supposedly obsoleted e.char)

reference: https://developer.mozilla.org/en-us/docs/web/events/keydown


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -