<body>
<input id="inp" width="11em" style='border-bottom-color: black'>
<script>
let inp=document.getElementById('inp');
inp.oninput=()=>{
let rText='';
let s=inp.value.replace(/\s+/g, '');
s.split('').forEach((it,i)=>{
if (i%3===0){
rText+=' ';
}
rText+=it;
});
inp.value=rText;
}
</script>
</body>