Here is clear cut solution
Masked Input[
^]
Here is manual js: This works on onblur:
<script src="http://code.jquery.com/jquery-latest.min.js"
<script type="text/javascript">
function formatPhone(obj) {
var numbers = obj.value.replace(/\D/g, ''),
char = { 0: '(', 3: ') ', 6: ' - ' };
obj.value = '';
for (var i = 0; i < numbers.length; i++) {
obj.value += (char[i] || '') + numbers[i];
}
}
</script>
And HTMl Code:
<input type="text" name="test" önblur="formatPhone(this);" />