JSFiddle - React, Tailwind, and code Playground

by Vijay Baskaran

HTML

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<input type="text" id="input" />

JavaScript

$('#input').on('keyup', function(e){
    var val = $(this).val();
    var newval = '';
    val = val.replace(/\s/g, '');
    for(var i=0; i < val.length; i++) {
        if(i%3 == 0 && i > 0) newval = newval.concat(' ');
        newval = newval.concat(val[i]);
    }
    $(this).val(newval);
})