C#
string temp = string.Empty;
// int i = value.Length;
if (value.Length == 3 || value.Length == 7)
{
if (temp.Length == 0)
{
temp = value;
}
temp += "-";
}
else
{
temp = value;
}
((Entry)sender).Text = temp;string temp = string.Empty;
// int i = value.Length;
if (value.Length == 3 || value.Length == 7)
{
if (temp.Length == 0)
{
temp = value;
}
temp += "-";
}
else
{
temp = value;
}
((Entry)sender).Text = temp;Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Rajat JaiswalRank #418 · 5.9K reputationPosted Feb 13, 2023, 10:14 AM EST
Hi,
You can try string format option like
Or create a property which will return format as shown below
string FormatPhoneNumber (temp) { var myformatedNumber = new StringBuilder(temp) ; myformatedNumber (6, '-'); myformatedNumber (3, ')'); myformatedNumber (0, '('); return myformatedNumber.ToString(); }Vishal JoshiRank #377 · 6.7K reputationPosted Feb 14, 2023, 3:07 AM EST
Hello akmal
You can try regex to mask the US Phone number. please check the below sample code.
var data = new string[] {"(123) 556-7890", "123 556 7890", "(123) 556- 7890"}; foreach (var s in data) { Console.WriteLine(Regex.Replace(s, @"\d(?!\d{0,3}$)", "X"));Result:
(XXX) XXX-7890
XXX XXX 7890
(XXX) XXX- 7890
Thanks