public bool CheckFormat(string cc, string phone, out string country) { country = string.Empty; using (List <CountryEntry> .Enumerator enumerator = this.items.GetEnumerator()) { while (enumerator.MoveNext()) { TerritoryInfo ti = new TerritoryInfo(cc, cc); CountryEntry current = enumerator.Current; if (current.CountryCode == cc && !string.IsNullOrEmpty(current.FormatRegexes)) { //boom! country = current.CountryName; char[] array = ";".ToCharArray(); string[] array2 = current.FormatRegexes.Split(array); string[] array3 = current.FormatStrings.Split(array); string[] array4 = current.PrefixRegexes.Split(array); ti.AllowedLengths = current.AllowedLengths; int num = array2.Length; char[] array5 = "#".ToCharArray(); for (int i = 0; i < num; i++) { string[] leadingDigitsPatterns = null; string matchPattern = array2[i]; string format = array3[i]; string text = array4[i].Trim(); if (text != "N/A") { leadingDigitsPatterns = text.Split(array5); } ti.addAvailableFormat(matchPattern, format, leadingDigitsPatterns); } using (List <FormatInfo> .Enumerator fenumerator = ti.AvailableFormats.GetEnumerator()) { while (fenumerator.MoveNext()) { FormatInfo fcur = fenumerator.Current; Regex regex = Enumerable.LastOrDefault <Regex>(fcur.LeadingDigitsPatterns); Match match; if (regex != null) { match = regex.Match(phone); if (!match.Success || match.Index != 0) { continue; } } match = fcur.NumberPattern.Match(phone); if (match.Success && match.Length == phone.Length) { return(true); } } } } } } return(false); }
public bool CheckFormat(string cc, string phone, out string country) { country = string.Empty; using (List<CountryEntry>.Enumerator enumerator = this.items.GetEnumerator()) { while (enumerator.MoveNext()) { TerritoryInfo ti = new TerritoryInfo(cc, cc); CountryEntry current = enumerator.Current; if (current.CountryCode == cc && !string.IsNullOrEmpty(current.FormatRegexes)) { //boom! country = current.CountryName; char[] array = ";".ToCharArray(); string[] array2 = current.FormatRegexes.Split(array); string[] array3 = current.FormatStrings.Split(array); string[] array4 = current.PrefixRegexes.Split(array); ti.AllowedLengths = current.AllowedLengths; int num = array2.Length; char[] array5 = "#".ToCharArray(); for (int i = 0; i < num; i++) { string[] leadingDigitsPatterns = null; string matchPattern = array2[i]; string format = array3[i]; string text = array4[i].Trim(); if (text != "N/A") { leadingDigitsPatterns = text.Split(array5); } ti.addAvailableFormat(matchPattern, format, leadingDigitsPatterns); } using (List<FormatInfo>.Enumerator fenumerator = ti.AvailableFormats.GetEnumerator()) { while (fenumerator.MoveNext()) { FormatInfo fcur = fenumerator.Current; Regex regex = Enumerable.LastOrDefault<Regex>(fcur.LeadingDigitsPatterns); Match match; if (regex != null) { match = regex.Match(phone); if (!match.Success || match.Index != 0) { continue; } } match = fcur.NumberPattern.Match(phone); if (match.Success && match.Length == phone.Length) { return true; } } } } } } return false; }