Welcome all. I have the following function to check input depending if it is numeric, alpha, alphanumeric and email:
function permite(e, permitidos) {
var key = e.keyCode || e.which;
if((key == 46) || (key == 8) || (key >= 37 && key <= 40))
return true;
var keychar = String.fromCharCode(key);
switch(permitidos) {
case 'num':
permitidos = /^[0-9]$/;
break;
case 'car':
permitidos = /^[\sa-zA-Z]$/;
break;
case 'num_car':
permitidos = /^[\sa-zA-Z0-9]$/;
break;
case 'correo':
permitidos = /^[a-zA-Z0-9._\-+@]$/;
break;
}
return permitidos.test(keychar);
}
The var names are in Spanish, but they are easy to understand.
The problem is as follows. The key code for "%" is 37 than the left arrow, and the key code for "(" 40 "is the same as the right arrow. Therefore, my function does not check"% "and" ("and this sucks". I do not know what to do, please help.
source
share