Search code examples
jquerykeyup

Why script not stop symbol with keyCode 69?


When i test my simple code, i get one problem - script should blocked symbols besides numbers, but he not blocked symbol e with keyCode 69.

Code:

$('#test').on('keyup', function(e) {
  console.log(e.keyCode);
  if( !((e.keyCode >=48 && e.keyCode <=57) || (e.keyCode >=96 && e.keyCode <=105) || e.keyCode == 8 || e.keyCode == 46) ){
    return false;
  }
});

Problem keyCode - 69. Why script not stop symbol e (keyCode 69) and how to solve a problem?


Solution

  • $('#test').on('keypress', function(e) {
      if( !(e.which >=48 && e.which <=57) ){
        return false;
      }
    });
    

    P.S.: bad night, bad question... thanks @JohnnyAW..