JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" value="53" onkeyup="this.value = digitGroup(this.value);">

JavaScript

function digitGroup(dInput) {
    var output = "";
    try {
        dInput = dInput.replace(/[^0-9]/g, ""); // remove all chars including spaces, except digits.
        var totalSize = dInput.length;
        for (var i = totalSize - 1; i > -1; i--) {
            output = dInput.charAt(i) + output;
            var cnt = totalSize - i;
            if (cnt % 3 === 0 && i !== 0) {
                output = "," + output; // seperator is " "
            }
        }
    } catch (err) {
        output = dInput; // it won't happen, but it's sweet to catch exceptions.
    }
    return output;
}