Limiting input to specified regexp with uppercase chars in IE
Posted
by pixelboy
on Stack Overflow
See other posts from Stack Overflow
or by pixelboy
Published on 2010-04-06T10:24:06Z
Indexed on
2010/04/06
10:33 UTC
Read the original article
Hit count: 286
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).keydown(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 !
© Stack Overflow or respective owner