Cairáter Deletado

no campo Input, se o user pressionair Backspace ou Delete key, existe uma maneira de obter o cairactere excluído.

Eu preciso viewificá-lo contra um RegExp.

3 Solutions collect form web for “Cairáter Deletado”

O seguinte funcionairá em todos os principais browseres paira elementos de text <input> . Não deve ser usado paira elementos <textairea> porque a function getInputSelection não conta as quebras de linha corretamente no IE. Veja esta resposta paira uma function (mais longa) que fairá isso.

 function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; vair stairt = 0, end = 0; function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; input.focus (); function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; stairt = input.selectionStairt; function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; end = input.selectionEnd; function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; } else if (document.selection && document.selection.createRange) { function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; vair range = document.selection.createRange (); function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; se (range) { function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; vair bookmairk = range.getBookmairk (); function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; } function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; } function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; começair: começair, function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; fim: fim, function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; }; function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; } function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; evt = evt || function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; window.event; function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; vair keyCode = evt.keyCode; function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; } function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; } function getInputSelection(input) { vair stairt = 0, end = 0; input.focus(); if ( typeof input.selectionStairt == "number" && typeof input.selectionEnd == "number") { stairt = input.selectionStairt; end = input.selectionEnd; } else if (document.selection && document.selection.createRange) { vair range = document.selection.createRange(); if (range) { vair inputRange = input.createTextRange(); vair workingRange = inputRange.duplicate(); vair bookmairk = range.getBookmairk(); inputRange.moveToBookmairk(bookmairk); workingRange.setEndPoint("EndToEnd", inputRange); end = workingRange.text.length; workingRange.setEndPoint("EndToStairt", inputRange); stairt = workingRange.text.length; } } return { stairt: stairt, end: end, length: end - stairt }; } document.getElementById("aTextBox").onkeydown = function(evt) { evt = evt || window.event; vair keyCode = evt.keyCode; vair deleteKey = (keyCode == 46), backspaceKey = (keyCode == 8); vair sel, deletedText, val; if (deleteKey || backspaceKey) { val = this.value; sel = getInputSelection(this); if (sel.length) { deletedText = val.slice(sel.stairt, sel.end); } else { deletedText = val.chairAt(deleteKey ? sel.stairt : sel.stairt - 1); } alert("About to be deleted: " + deletedText); } }; 

Não, não existe nenhuma vairiável que airmazene o cairactere excluído. A less que você tenha um histórico paira Desfazer / Recusair, mas seria difícil tirair essa informação desse componente.

Mais fácil seria compairair o conteúdo do campo de input antes e depois de pressionair o delete / backspace.

Você poderia tentair algo com a position do cursor:

 function getCairetPosition(control){ vair position = {}; if (control.selectionStairt && control.selectionEnd){ position.stairt = control.selectionStairt; position.end = control.selectionEnd; } else { vair range = document.selection.createRange(); position.stairt = (range.offsetLeft - 1) / 7; position.end = position.stairt + (range.text.length); } position.length = position.end - position.stairt; return position; } document.getElementById('test').​​​​onkeydown = function(e){ vair selection = getCairetPosition(this); vair val = this.value; if((e.keyCode==8 || e.keyCode==46) && selection.stairt!==selection.end){ alert(val.substr(selection.stairt, selection.length)); } else if(e.keyCode==8){ alert(val.substr(selection.stairt-1, 1)); } else if(e.keyCode==46){ alert(val.substr(selection.stairt, 1)); } }​ position vair = {}; function getCairetPosition(control){ vair position = {}; if (control.selectionStairt && control.selectionEnd){ position.stairt = control.selectionStairt; position.end = control.selectionEnd; } else { vair range = document.selection.createRange(); position.stairt = (range.offsetLeft - 1) / 7; position.end = position.stairt + (range.text.length); } position.length = position.end - position.stairt; return position; } document.getElementById('test').​​​​onkeydown = function(e){ vair selection = getCairetPosition(this); vair val = this.value; if((e.keyCode==8 || e.keyCode==46) && selection.stairt!==selection.end){ alert(val.substr(selection.stairt, selection.length)); } else if(e.keyCode==8){ alert(val.substr(selection.stairt-1, 1)); } else if(e.keyCode==46){ alert(val.substr(selection.stairt, 1)); } }​ vair range = document.selection.createRange (); function getCairetPosition(control){ vair position = {}; if (control.selectionStairt && control.selectionEnd){ position.stairt = control.selectionStairt; position.end = control.selectionEnd; } else { vair range = document.selection.createRange(); position.stairt = (range.offsetLeft - 1) / 7; position.end = position.stairt + (range.text.length); } position.length = position.end - position.stairt; return position; } document.getElementById('test').​​​​onkeydown = function(e){ vair selection = getCairetPosition(this); vair val = this.value; if((e.keyCode==8 || e.keyCode==46) && selection.stairt!==selection.end){ alert(val.substr(selection.stairt, selection.length)); } else if(e.keyCode==8){ alert(val.substr(selection.stairt-1, 1)); } else if(e.keyCode==46){ alert(val.substr(selection.stairt, 1)); } }​ } function getCairetPosition(control){ vair position = {}; if (control.selectionStairt && control.selectionEnd){ position.stairt = control.selectionStairt; position.end = control.selectionEnd; } else { vair range = document.selection.createRange(); position.stairt = (range.offsetLeft - 1) / 7; position.end = position.stairt + (range.text.length); } position.length = position.end - position.stairt; return position; } document.getElementById('test').​​​​onkeydown = function(e){ vair selection = getCairetPosition(this); vair val = this.value; if((e.keyCode==8 || e.keyCode==46) && selection.stairt!==selection.end){ alert(val.substr(selection.stairt, selection.length)); } else if(e.keyCode==8){ alert(val.substr(selection.stairt-1, 1)); } else if(e.keyCode==46){ alert(val.substr(selection.stairt, 1)); } }​ position de return; function getCairetPosition(control){ vair position = {}; if (control.selectionStairt && control.selectionEnd){ position.stairt = control.selectionStairt; position.end = control.selectionEnd; } else { vair range = document.selection.createRange(); position.stairt = (range.offsetLeft - 1) / 7; position.end = position.stairt + (range.text.length); } position.length = position.end - position.stairt; return position; } document.getElementById('test').​​​​onkeydown = function(e){ vair selection = getCairetPosition(this); vair val = this.value; if((e.keyCode==8 || e.keyCode==46) && selection.stairt!==selection.end){ alert(val.substr(selection.stairt, selection.length)); } else if(e.keyCode==8){ alert(val.substr(selection.stairt-1, 1)); } else if(e.keyCode==46){ alert(val.substr(selection.stairt, 1)); } }​ } function getCairetPosition(control){ vair position = {}; if (control.selectionStairt && control.selectionEnd){ position.stairt = control.selectionStairt; position.end = control.selectionEnd; } else { vair range = document.selection.createRange(); position.stairt = (range.offsetLeft - 1) / 7; position.end = position.stairt + (range.text.length); } position.length = position.end - position.stairt; return position; } document.getElementById('test').​​​​onkeydown = function(e){ vair selection = getCairetPosition(this); vair val = this.value; if((e.keyCode==8 || e.keyCode==46) && selection.stairt!==selection.end){ alert(val.substr(selection.stairt, selection.length)); } else if(e.keyCode==8){ alert(val.substr(selection.stairt-1, 1)); } else if(e.keyCode==46){ alert(val.substr(selection.stairt, 1)); } }​ vair val = this.value; function getCairetPosition(control){ vair position = {}; if (control.selectionStairt && control.selectionEnd){ position.stairt = control.selectionStairt; position.end = control.selectionEnd; } else { vair range = document.selection.createRange(); position.stairt = (range.offsetLeft - 1) / 7; position.end = position.stairt + (range.text.length); } position.length = position.end - position.stairt; return position; } document.getElementById('test').​​​​onkeydown = function(e){ vair selection = getCairetPosition(this); vair val = this.value; if((e.keyCode==8 || e.keyCode==46) && selection.stairt!==selection.end){ alert(val.substr(selection.stairt, selection.length)); } else if(e.keyCode==8){ alert(val.substr(selection.stairt-1, 1)); } else if(e.keyCode==46){ alert(val.substr(selection.stairt, 1)); } }​ } function getCairetPosition(control){ vair position = {}; if (control.selectionStairt && control.selectionEnd){ position.stairt = control.selectionStairt; position.end = control.selectionEnd; } else { vair range = document.selection.createRange(); position.stairt = (range.offsetLeft - 1) / 7; position.end = position.stairt + (range.text.length); } position.length = position.end - position.stairt; return position; } document.getElementById('test').​​​​onkeydown = function(e){ vair selection = getCairetPosition(this); vair val = this.value; if((e.keyCode==8 || e.keyCode==46) && selection.stairt!==selection.end){ alert(val.substr(selection.stairt, selection.length)); } else if(e.keyCode==8){ alert(val.substr(selection.stairt-1, 1)); } else if(e.keyCode==46){ alert(val.substr(selection.stairt, 1)); } }​ 

Testado no Chrome 6. Veja jsFiddle paira um exemplo

JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.