<p id="input">47534532</p>
let input = document.querySelector("#input");
let number = input.innerText;

input.innerText = formatPriceNumber(number);

function formatPriceNumber(priceNumberString) {
	var cleaned = priceNumberString.replace(/\D/g, "");
	var match = cleaned.match(/^(\d{2,3})(\d{3})(\d{3})$/);
	if (match) {
		return `$${match[1]},${match[2]},${match[3]}`;
	}
	return null;
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.