This is my code and how I used it: It is working and you can use it too.
using System.Text.RegularExpressions;
...........
public string Phone
{
get { return FormatUSPhone(telPhone.Telephone); }
}
.......
public string FormatUSPhone(string num)
{
//first we must remove all non numeric characters
num = num.Replace("(", "").Replace(")","").Replace("-","");
string results = string.Empty;
string formatPattern = @"(\d{3})(\d{3})(\d{4})";
results = Regex.Replace(num, formatPattern, "($1) $2-$3");
return results;
}
|