public static bool CheckNumberGroupingIsValid( PhoneNumber number, String candidate, PhoneNumberUtil util, CheckGroups checker) { // TODO: Evaluate how this works for other locales (testing has been limited to NANPA regions) // and optimise if necessary. StringBuilder normalizedCandidate = PhoneNumberUtil.NormalizeDigits(candidate, true /* keep non-digits */); String[] formattedNumberGroups = PhoneNumberMatcher.GetNationalNumberGroups(util, number, null); if (checker(util, number, normalizedCandidate, formattedNumberGroups)) { return(true); } // If this didn't pass, see if there are any alternate formats, and try them instead. var alternateFormats = MetadataManager.GetAlternateFormatsForCountry(number.CountryCode); if (alternateFormats != null) { foreach (var alternateFormat in alternateFormats.NumberFormatList) { formattedNumberGroups = GetNationalNumberGroups(util, number, alternateFormat); if (checker(util, number, normalizedCandidate, formattedNumberGroups)) { return(true); } } } return(false); }
public static bool Verify( this Leniency leniency, PhoneNumber number, string candidate, PhoneNumberUtil util, PhoneNumberMatcher matcher) => util.Verify(leniency, number, candidate, util, matcher);