javascript - prevent @ to be entered into input field? -


i want prevent @ entered input. doesn't work, idea why?

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

https://jsfiddle.net/r82wtea3/2/

you need pass parameter event function:

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

i suggest use event.which instead of event.keycode better compatibility. here's updated fiddle. have used keypress event instead of keyup.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -