Currency Input Formatter
A currency input that formats the amount and shows a preview.
Requires Bootstrap 5. Add the CDN tags below to your page (styles in
<head>, scripts before </body>). The downloaded file already includes them.<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script><div class="card border-0 shadow-sm" style="max-width:320px"><div class="card-body">
<label class="form-label small fw-semibold">Amount</label>
<div class="input-group"><span class="input-group-text">$</span><input class="form-control" id="curInput" placeholder="0.00"><span class="input-group-text">USD</span></div>
<small class="text-secondary" id="curOut">Enter an amount</small>
</div></div>var i=document.getElementById('curInput'),o=document.getElementById('curOut');
i.addEventListener('input',function(){var n=parseFloat(i.value.replace(/[^0-9.]/g,''))||0;o.textContent=n?'Formatted: '+n.toLocaleString('en-US',{style:'currency',currency:'USD'}):'Enter an amount'});
i.addEventListener('blur',function(){var n=parseFloat(i.value.replace(/[^0-9.]/g,''));if(n)i.value=n.toFixed(2)});Free to use.This component uses Bootstrap 5 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.