using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace PhilExampleCrawler.Common.Models { public static class Validator { private const string ALLOWED = "0123456789"; /// Removes any character that is not contained in "0123456789" public static string PhoneNumber_Normalize(this string phone) { if (string.IsNullOrEmpty(phone)) return ""; string p = ""; for (int i = phone.Length - 1; i >= 0; i--) if (ALLOWED.Any(c => c == phone[i])) p = phone[i] + p; return p; //=> phone.Trim().TrimStart('+').TrimStart('0') } } }