Exemplo n.º 1
0
        /// <summary>
        /// Returns the PhoneNumbers.PhoneNumber object of the phonenumber
        /// </summary>
        /// <param name="phoneUtil">PhoneUtil instance</param>
        /// <param name="numberString">Phonenumber</param>
        /// <param name="regionCodes">The region code for global networks</param>
        /// <returns>Null if it was invalid phonenumber</returns>
        public static PhoneNumbers.PhoneNumber GetValidMobileNumber(this PhoneNumbers.PhoneNumberUtil phoneUtil, string numberString, string[] regionCodes)
        {
            var number = phoneUtil.GetValidNumber(numberString, regionCodes);

            if (number == null)
            {
                return(null);
            }

            return(phoneUtil.GetNumberType(number) == PhoneNumberType.MOBILE
                                ? number
                                : null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tries get the PhoneNumber object if the phonenumber is a valid phoneNumber for the regions specified
        /// </summary>
        /// <param name="phoneUtil"></param>
        /// <param name="numberString"></param>
        /// <param name="regionCodes">The region code for global networks</param>
        /// <param name="phoneNumber">PhoneNumber object</param>
        /// <returns>True if successful; else false</returns>
        public static bool TryGetValidMobileNumber(this PhoneNumbers.PhoneNumberUtil phoneUtil, string numberString, string[] regionCodes, out PhoneNumbers.PhoneNumber phoneNumber)
        {
            phoneNumber = null;

            var number = phoneUtil.GetValidNumber(numberString, regionCodes);

            if (number == null)
            {
                return(false);
            }

            return(phoneUtil.GetNumberType(number) == PhoneNumberType.MOBILE);
        }