I am trying to detect when a user pressed the @ key in a text box. I can use JQuery to handle the keyup event like so...
$('#target').keyup(function(event) {
});
But what do I do from here to test for the @ character? I know I can use event.which
to get a key code. But in this instance I would need to also check for shift - technically this is not a problem, but I know the @ key can move around with different language settings and I am worried that this may prove to be inconsistent. Maybe I am worried wrongly, and I can rely on it always being SHIFT + 192
?
Ideally I would like something like the following to allow for easier configuration later on...
event.something == "@";
Thanks for any help
Try checking for event.which == 64
, as 64 is the ascii of the at sign (not tested, but should work)
$("#target").keypress(function(event) {
if ( event.which == 64 ) {
alert("weehee");
}
});
If this fails, you can check after keyup (when user releases key), if the last character he inputted into the text field is a @ sign, and act accordingly.
Shai
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With