JSFiddle - React, Tailwind, and code Playground

by DefuZe

HTML

<script src="https://rawgithub.com/digitalBush/jquery.maskedinput/master/dist/jquery.maskedinput.min.js"></script>
<input id="code" />

JavaScript

jQuery(document).ready(function () {
    jQuery("#code").mask("")
        .keydown(function () {
        var $elem = $(this);
        var a = this.value.replace(/\D/g, "").length;
        setTimeout(function () {
            var n = $elem.val().replace(/\D/g, "").length;
            if (n !== a && (n === 5 || n === 4)) {
                var mask = (n === 4 ? "99-99?9" : "999-99");
                $elem.mask(mask);
            }
        }, 1);
    });
});