I’m trying to limit what our users will be able to type in inputs, using javascript/jquery.
Problem is, I have to limit this to Uppercase chars only, and numbers.
Here’s what I coded previously :
$(input).keypress(function(e){
if ($(input).attr("class")=="populationReference"){
var ValidPattern = /^[A-Z_0-9]*$/;
var char = String.fromCharCode(e.charCode);
if (!ValidPattern.test(char) && e.charCode!=0){
return false;
e.preventDefault();
}
}
});
If Firefox supports charCode, IE doesn’t. How then, could I test if the user is typing uppercase or lowercase characters ?
Thanks for any help !
From the jquery manual for
keypress():In other words, if you are using jquery, you are safe to use
e.whichto return the character code, so in your case:is the change to make.
But personally, I would avoid punishing users for lower-case input by converting it for them. Maybe add this modification: