Example #1
0
        private static bool MobileValidator(string phoneNumber, List <IRegionValidator> validators, RegionalOptions options = null)
        {
            if (options == null)
            {
                options = RegionalOptions.Default;
            }

            phoneNumber = PreValidateHandling(phoneNumber, options);
            var normalizedNumber = TelephoneNormalizer.ToPhoneNumberNormalization(phoneNumber, options, "+");

            if (!(PhoneNumberValidateLength(phoneNumber, options) && PhoneNumberValidateFormat(phoneNumber, options)))
            {
                return(false);
            }

            foreach (var validator in validators)
            {
                if (validator.IsMobileNumber(normalizedNumber, options.AllowNoSign))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Validates only the total length of the phone number
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static bool PhoneNumberValidateLength(string phoneNumber, TelephoneOptions options = null)
        {
            phoneNumber = PreValidateHandling(phoneNumber, options);

            var normalized = TelephoneNormalizer.ToPhoneNumberNormalization(phoneNumber, options);

            if (normalized.Length < MinimumPhoneNumberLength || normalized.Length > MaximumPhoneNumberLength)
            {
                return(false);
            }
            return(true);
        }