Please see my comment to the question. Deleting wrong character is not a valid option. Instead, you should filter out some unwanted characters, so they won't even appear in the input.
For this purpose, your event handler should have an additional argument (which you need anyway), the instance of the event object, let's say, its name is
. On certain condition, you want to block some character from input. This is done by calling the function
(See also: Event.defaultPrevented — Web APIs | MDN
], Event.stopPropagation() — Web APIs | MDN
It does not matter if you do it using jQuery or not. Please see this jQuery help page: .keypress() | jQuery API Documentation
On this page, please find the sample code fragment with
from this code sample, you will see how to use this technique with jQuery.