Пример #1
0
 public void RegisterRegions(Country country, IExceptionalCountryCode exceptionalCountry)
 {
     //if (_exceptionalCountries.ContainsKey(country))
     //    _exceptionalCountries[country].Add(exceptionalCountry);
     //else _exceptionalCountries.Add(country, new List<IExceptionalCountryCode> {exceptionalCountry});
     _exceptionalCountries.Add(country, exceptionalCountry);
 }
Пример #2
0
 private static bool MatchCombination(string phoneNumber, IExceptionalCountryCode definition)
 {
     return(definition.InternationalPrefixes.Any(internationalPrefix =>
                                                 definition.CountryCodes.Any(countryCode =>
                                                                             phoneNumber.StartsWith(internationalPrefix + countryCode)
                                                                             )
                                                 ));
 }
Пример #3
0
        /// <summary>
        /// Find countries that do not follows the ITU-T recommendations
        /// </summary>
        /// <param name="selectedException"></param>
        /// <param name="phoneNumber"></param>
        /// <returns></returns>
        private static bool IsExceptionalPhoneNumber(out IExceptionalCountryCode selectedException, string phoneNumber)
        {
            foreach (var definition in ExceptionalContainer.GetAllDefinitions())
            {
                if (definition.CustomValidation != null &&
                    definition.CustomValidation(phoneNumber))
                {
                    selectedException = definition;
                    return(true);
                }

                if (MatchCombination(phoneNumber, definition))
                {
                    selectedException = definition;
                    return(true);
                }
            }

            selectedException = null;
            return(false);
        }