JSFiddle - React, Tailwind, and code Playground

by ahmednuaman

HTML

<p>
            $<input id="input" type="number" />
        </p>
        <p>
            <button>
                I do nothing!
            </button>
        </p>
        <script src="https://raw.github.com/kvz/phpjs/master/functions/strings/number_format.js"></script>

JavaScript

var i = document.getElementById('input');

i.onblur = function() {
    i.type = 'text';

    i.value = number_format(i.value);
}

i.onfocus = function() {
    var v = Number(i.value.replace(/\D/, ''));

    i.type = 'number';

    i.value = v > 0 ? v : '';
}