JSFiddle - React, Tailwind, and code Playground

by Jake Wolpert

HTML

<textarea>12</textarea>
<input type=text value=23>

JavaScript

$(function () {
    $(':text,textarea').bind('paste input', removeAlphaChars);
})

function removeAlphaChars(e) {
    var self = $(this);
    setTimeout(function () {
        var initVal = self.val(),
            outputVal = initVal.replace(/[^0-9]/g, "");
        if (initVal != outputVal) self.val(outputVal);
    });
}