Can anyone help me?
This doesn’t seem to work:
switch (parseInt(charCode))
{
case (charCode >= 65 && charCode <=90): //UPPERCASE
alert("UP");
break;
case (charCode >= 97 && charCode <=122): //LOWERCASE
alert("LO");
break;
case (charCode >= 48 && charCode <=57): //NNUMBERS
alert("NUM");
break
}
Thanks
[edit] Let’s add this disclaimer: this use of
switchis considered EVIL or ABUSIVE. Some Disciples Of The Javascript also consider the use of ternaries as a major SIN. So beware of using them, because hell may await you, so the Gospel goes.You can use
switchlike this 1:it’s pretty bulky. You don’t have to use
parseIntif you derivecharCodecame fromevent.keyCode. If you need to useparseInt, don’t forget to provide the radix, or better still, useNumberto convert to a number.Anyway using a ternary is an alternative for this:
[edit] Let’s see if the following alternative can satisfy the church of Javascript Coders…
Another alternative is using a
RegExpwith the character derived from thekeyCode:As a last alternative (man, javascript is so versatile!) I present:
1 some notes on that ‘trick’