I know I'm a little late to the party.
An HTML5 jAndy example is probably the best answer for browsers that support it. Josaph's answer to JavaScript was good in that it inspired my answer to the solution to the add-on and my problem.
The next one discards the input that matches the regular expression (not a digit, replaced by an empty string), and is called anytime there, even from paste.
function stripNonNumeric() { this.value = this.value.replace(/\D+/g, ''); } var txtChar = document.getElementById("txtChar"); if (txtChar.addEventListener) { txtChar.addEventListener("input", stripNonNumeric); } else if (txtChar.attachEvent) { txtChar.attachEvent("oninput", stripNonNumeric); }
I'm not a guy from JavaScript, I'm not sure if this is a good way to solve a problem or if there are performance issues. However, this works for me.
titanofold
source share