I am looking for a simple maybe JS to forbid apostrophe onKeyUp or OnKeyPress kind of thing. For ex, every time user presses a key if it was apostrophe (Jame’s Pizza) replace it with space. I don’t want to process it in PHP
I found a code but it ties the JS to the textfield Name which I don’t want. I need something global,
I am looking for a simple maybe JS to forbid apostrophe onKeyUp or OnKeyPress
Share
It’s always better to prevent the keystroke than to retroactively delete it. To accomplish this, you need to intercept the
keypressevent (keyupis too late):http://jsfiddle.net/TSB9r/
If you only want to stop the
'from appearing in the box but would like the keypress event to propagate to parent elements, replace thereturn false;withevent.preventDefault();. (suggested by Eivind Eidheim Elseth in the comments)