/// <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> /// Checks if the input is an internal number. /// If not calls a check if input is an external number. /// </summary> /// <param name="input"></param> /// <returns>Information about the type of number the input is</returns> public static NumberStringType IsValidPhoneNumber(string input) { NumberStringType result = NumberStringType.NOT_POSSIBLE; if (!string.IsNullOrEmpty(input)) { result = INTERNAL_NUMBER_EX.Match(input).ToString() == input ? NumberStringType.INTERNAL : IsValidExternalNumber(input); } return(result); }
/// <summary> /// Checks if the content of the clipboard can be used as a number and sets the current number if so. /// </summary> private void ProcessClipboardContent() { NumberStringType type = NumberStringUtils.IsValidPhoneNumber(_currentClipboardContent); switch (type) { case NumberStringType.NOT_POSSIBLE: // Do nothing because the clipboard does not contain a number break; case NumberStringType.NOT_VALID: // Do nothing because the content of the clipboard is not a valid number // Here the option could be implementet, to inform the user about the fact he has copied a possible but not valid number. // It could be a valid number in another country. This could be checked. break; default: CurrentNumber = new Number(NumberStringUtils.FormatNumberString(_currentClipboardContent), type); Clipboard.Clear(); // Bugfix to stop randomly appearing balllon tipps if you copy a valid external/internal number break; } }
public Number(string numberString, NumberStringType type) { NumberString = numberString; Type = type; }