public void Should30() { var phoneNumber = _phoneNumberUtil.Parse(NumberToParse, null); var isValidNumber = _phoneNumberUtil.IsPossibleNumber(phoneNumber); Assert.That(isValidNumber, Is.True); }
/// <summary> /// Checks if the input is an external number. /// </summary> /// <param name="input"></param> /// <returns>Information about the type of number the input is</returns> private static NumberStringType IsValidExternalNumber(string input) { PhoneNumberUtil util = PhoneNumberUtil.GetInstance(); NumberStringType result = NumberStringType.NOT_POSSIBLE; if (PHONE_NUMBER_EX.Match(input).ToString() == input) { string numberString = FormatNumberString(input); try { PhoneNumber numberProto = util.Parse(numberString, Config.Instance.DefaultRegion); if (util.IsPossibleNumber(numberProto)) { if (util.IsValidNumber(numberProto)) { result = NumberStringType.EXTERNAL; } else { result = NumberStringType.NOT_VALID; } } } catch (Exception e) { ClassLogger.Error(LogMessages.ErrorPhoneNumberValid, e.ToString()); result = NumberStringType.NOT_POSSIBLE; } } return(result); }
/// <summary> /// Validates user's phone number whether it is correct or not. /// </summary> /// <param name="phoneNumber">A string containing the phone number.</param> /// <returns>true if provide phone number is valid; otherwise false.</returns> public static bool ValidatePhoneNumber(string phoneNumber) { PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.GetInstance(); try { PhoneNumber phoneNumberInfo = phoneNumberUtil.Parse(phoneNumber, null); bool isPossiblePhoneNumber = phoneNumberUtil.IsPossibleNumber(phoneNumberInfo); bool isValidPhoneNumber = phoneNumberUtil.IsValidNumber(phoneNumberInfo); if (isPossiblePhoneNumber || isValidPhoneNumber) { var countryCode = phoneNumberInfo.CountryCode.ToString(); var numberWithoutCountryCode = phoneNumber.Substring(countryCode.Length + 1, phoneNumber.Length - (countryCode.Length + 1)); if (numberWithoutCountryCode.Substring(0, 1) == "0") { return(false); } return(true); } return(false); } catch (Exception exp) { LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), exp.Message); return(false); } }
public IEnumerable <PersonModel> GetAnswerToCodingAssessment() { var ids = this.GetAllIds(); var people = this.GetFromIds(ids); return(people.Where(p => _phoneNumberUtil.IsPossibleNumber(p.Number, "US")) .OrderBy(p => p.Age) .Take(5) .OrderBy(p => p.Name)); }
static bool IsValidUSNumber(string number) { PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.GetInstance(); PhoneNumber parsedNumber; try { parsedNumber = phoneNumberUtil.Parse(number, "US"); } catch (NumberParseException) { return(false); } // Checking if a number is a possible US number is a fast and reasonably accurate way to determine validity return(phoneNumberUtil.IsPossibleNumber(parsedNumber)); }
public bool BeAValidPhoneNumber(string phonenumber) { PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.GetInstance(); return(phoneNumberUtil.IsPossibleNumber(phonenumber, "AU")); }
private static bool BeAPhoneNumber(string value) { //To be comprehensive, this should probably be validated by a service like Twilio return(PhoneNumberUtil.IsPossibleNumber(value, "BE")); }