JSFiddle - React, Tailwind, and code Playground
HTML
<input class="numeric-textbox">
JavaScript
$('.numeric-textbox').bind('keypress paste', function (e) {
if(e.keyCode == '9' || e.keyCode == '16'){
return;
}
var code;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
if(e.which == 46)
return false;
if (code == 8 || code == 46)
return true;
if (code < 48 || code > 57)
return false;
},
if (!e.originalEvent.clipboardData.getData('Text').match(/[^\d]/)) {
e.preventDefault();
}
});
function paste(obj) {
var totalCharacterCount = window.clipboardData.getData('Text');
var strValidChars = "0123456789";
var strChar;
var FilteredChars = "";
for (i = 0; i < totalCharacterCount.length; i++) {
strChar = totalCharacterCount.charAt(i);
if (strValidChars.indexOf(strChar) != -1) {
FilteredChars = FilteredChars + strChar;
}
}
obj.value = FilteredChars;
return false;
}