JSFiddle - React, Tailwind, and code Playground

HTML

<input id="theInput" />

JavaScript

$('#theInput').blur(function()
{
    $(this).val(function(i, v)
    {
        var v = v.replace(/[^\d]/g, '').match(/.{1,4}/g);
        return v ? v.join('-') : '';
    });
});