Eunice Chia Eunice Chia - 1 year ago 72
jQuery Question

prevent @ to be entered into input field?

I want to prevent

to be entered into
. But it doesn't work, any idea why?

$(function() {
$(document).on('keyup', '[placeholder="x"]', function() {
if (event.keyCode === 64) {

Answer Source

You also need to pass parameter event to the function:

$(document).on('keypress', '[placeholder="x"]', function(event) { /*...*/ });

I suggest you to use event.which instead of event.keyCode for better compatibility. Here's your updated fiddle. I have used keypress event instead of keyup.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download