Keydown Event Codes
In the KeyDown event of the textbox, I can check the keyCode range
For example,
if (e.keyCode == 90 to 97 || e.keyCode == 104 to 110)
How to write it down correctly?
+2
Hitz
source
to share
4 answers
var inInterval = function (code, min, max) {
return code >= min && code <= max;
};
if (inInterval(e.keyCode, 90, 97) || inInterval(e.keyCode, 104, 110))
Or, slightly better:
var interval = function (min, max) {
return {
min: min,
max: max,
contains : function (elem) {
return this.min <= elem && elem <= this.max;
}
};
};
interval(90, 98).contains(92); // true
interval(90, 98).contains(15); // false
+6
IonuΘ G. Stan
source
to share
if ((e.keyCode > 89 && e.keyCode < 98) || (e.keyCode > 103 && e.keyCode < 111))
or
if ((e.keyCode >= 90 && e.keyCode <= 97) || (e.keyCode >= 104 && e.keyCode <= 110))
+1
karim79
source
to share
if ((90 <= e.keyCode && e.keyCode <= 97) || (104 <= e.keyCode && e.keyCode <= 110))
0
Dominic Rodger
source
to share
var myKeycodes = [1,2,3,4,5,6];
if(myKeycodes.indexOf(e.keyCode) != -1){
// your keycode is in the array, do stuff
}
0
inkedmn
source
to share