<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">$(function() {
$("input[name='phone']").keyup(function() {
var curchr = this.value.length;
var curval = $(this).val();
if (curchr == 3) {
$("input[name='phone']").val("(" + curval
+ ")" + " ");
} else if (curchr == 9) {
$("input[name='phone']").val(curval + "-");
}
});
});</script>