in in Input field, if the user presses Backspace or Delete key, is there a way to get the deleted character.
I need to check it against a RegExp.
in in Input field, if the user presses Backspace or Delete key, is there a way to get the deleted character.
I need to check it against a RegExp.
The following will work in all major browsers for text
<input>
elements. It shouldn't be used for<textarea>
elements because thegetInputSelection
function doesn't account for line breaks correctly in IE. See this answer for a (longer) function that will do this.No, there is no variable that stores the deleted char. Unless you have a history for Undo/Redo, but it would be difficult to get the information out of that component.
Easiest would be to compare the contents of the input field before and after delete/backspace have been pressed.
You could try something with the caret position:
Tested on Chrome 6. See jsFiddle for an example