Phone Input Formatter
An input that live-formats digits into a phone number pattern.
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:340px"><div class="card-body"><label class="form-label small fw-semibold">Phone</label><input class="form-control" id="imInput" placeholder="(000) 000-0000"></div></div>var i=document.getElementById("imInput");i.addEventListener("input",function(){var d=i.value.replace(/\D/g,"").slice(0,10),o=d;if(d.length>6)o="("+d.slice(0,3)+") "+d.slice(3,6)+"-"+d.slice(6);else if(d.length>3)o="("+d.slice(0,3)+") "+d.slice(3);else if(d.length>0)o="("+d;i.value=o});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.