I have the following code:
function noNumbers(e)
{
var charCode = (e.which) ? e.which :
((e.charCode) ? e.charCode :
((
Why not handle the input event instead? This method will handle live changes via keyboard entry, cut, paste, etc.
(function() {
var textBox = document.getElementById("text-box");
textBox.addEventListener("input", function(e) {
var val = this.value,
rx = /[^\d]/g;
if (rx.test(val)) {
var pos = this.selectionStart;
this.value = val.replace(rx, "");
this.selectionStart = pos;
this.selectionEnd = pos - 1;
}
});
})();