JSFiddle - React, Tailwind, and code Playground
by nobuts
HTML
Enter Phone# : <input type="text" id="txtval" value="1234567890" />
<input type="button" value="Format Phone" id="btnval" />
<div class="fill"></div>
CSS
.fill {
background-color: lightgray;
margin: 20px;
text-align: center;
}
JavaScript
//var phone = "1234567899";
$(document).ready(function() {
$('#btnval').click(function() {
var $phone = $('#txtval').val();
var formattedPhone = $phone.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3");
$('.fill').text(formattedPhone);
});
});