I have solved this problem with the below code...
function FormatPhone(e) {
evt = e || window.event;
var keyPressed = evt.which || evt.keyCode;
if(((keyPressed >= 97) && (keyPressed <= 122)) || ((keyPressed >= 65) && (keyPressed <= 90))) {
return false;
}
else {
if (keyPressed == 8 || keyPressed == 37) {
return;
}
var target = evt.target || evt.srcElement;
phone = target.value;
if (phone.length == 1 && phone != "(") {
target.value = "(" + phone;
}
else if (phone.length == 4 && phone.substring(0, 1) == "(" && !isNaN(phone.substring(1, 4))) {
target.value = phone + ") ";
}
else if (phone.length == 9 && phone.substring(0, 1) == "(" && !isNaN(phone.substring(1, 4)) && phone.substring(4, 5) == ")" && !isNaN(phone.substring(6, 9))) {
target.value = phone + "-";
}
}
}
and passing the event in the page_load
txtPhone2.Attributes.Add("Onkeypress", "return FormatPhone(event)");
Thanks,
Nag