JSFiddle - React, Tailwind, and code Playground
JavaScript
var x = '301.474.4062';
x = x.replace(/[^\d]+/g, '')
.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
alert(x);
var x = '301.474.4062';
x = x.replace(/[^\d]+/g, '')
.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
alert(x);