JSFiddle - React, Tailwind, and code Playground
by efwjames
HTML
<input type="text" id="phone" maxlength="11">
JavaScript
var phone = "6129872395";
$('#phone').keyup(function (e) {
var currentval = $(this).val();
if (e.keyCode == 46) {} else {
if (currentval.length == 4 && $(this).val().charAt(3) !== ' ') {
$(this).val(currentval.substr(0,3) + ' ' + currentval.charAt(3));
} else {
$(this).val(currentval);
}
}
});