javascript keypress function: case-insensitive a-z, numbers and a few special chars?
Posted
by
user239831
on Stack Overflow
See other posts from Stack Overflow
or by user239831
Published on 2011-01-02T08:26:48Z
Indexed on
2011/01/02
8:53 UTC
Read the original article
Hit count: 304
hey guys,
$('.s').keyup(function(e) {
if (!/[A-Za-z0-9]/.test(String.fromCharCode(e.which))) {
return false;
}
I wonder what is the best regex solution for my application. I have an ajax-based search that should just trigger the search when actual characters are pressed like a-Z (upper and lowercase), numbers and maybe a questionmark, a dash(hyphen), and an exclamation mark. Also the spacebar should be enabled.
Otherwise the ajax search would be triggered as well if the shift-, option, or control-key, is pressed.
What's the easiest regex pattern to understand here? thank you for your help
© Stack Overflow or respective owner