JSFiddle - React, Tailwind, and code Playground
HTML
<input id='name' type='text' />
JavaScript
$(document).ready(function () {
$('#name').bind('keypress', function (e) {
// Filter non-digits from input value.
if ($('#name').val().length == 0) {
if (e.which == 32) { //space bar
e.preventDefault();
}
} else {
$(this).val($(this).val().replace(/[^A-Za-z0-9_\s]/, ''))
}
});
});