JSFiddle - React, Tailwind, and code Playground
HTML
<input class="element text medium" id="test" name="name" type="text">
JavaScript
var downed = 0;
$('#test').keydown(function () {
downed++;
if(downed == 2){
var reformat = this.value.replace(/(\d{3}\s*)/g, function(match){
console.log("match before" + match);
if(match.match(/\s/)){return match;}
return match + " ";
});
console.log(reformat);
this.value = reformat;
downed = 0;
}
});