Created
June 17, 2020 07:52
-
-
Save eugen1408/4213472ab572e8eab66e38c1a5e92a48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string FormatPhone(string phoneString) | |
{ | |
if (string.IsNullOrWhiteSpace(phoneString)) return phoneString; | |
var phoneReplaced = phoneString.Replace(" ", "").Replace("-", "").Replace(")", "").Replace("(", "").Replace("+", ""); | |
if (phoneReplaced.Length == 10 && (phoneReplaced[0] == '9')) return "+7" + phoneReplaced; | |
else if ((phoneReplaced.Length == 11 && (phoneReplaced[0] == '8'))) return "+7" + phoneReplaced.Substring(1); | |
else return phoneReplaced.StartsWith("7") ? $"+{phoneReplaced}" : phoneReplaced; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment