JSFiddle - React, Tailwind, and code Playground

by vladkras

HTML

<input type="text" id="txt" onkeyup="addComma(this);" />

JavaScript

function addComma(txt) {
    txt.value = txt.value.replace(",", "").replace(/(\d+)(\d{3})/, "$1,$2");
}