Interface PhoneFormatter

All Known Implementing Classes:
PhoneFormatterImpl

public interface PhoneFormatter
  • Method Details

    • formatE164

      Optional<String> formatE164(String number, @Nullable @Nullable String defaultRegion)
      Tries to format a phone number in E.164 format. If not possible, Optional.empty() is returned.
      Parameters:
      number - The phone number to format.
      defaultRegion - The default region (i.e. "CH" for switzerland).
      Returns:
      the formatted number or Optional.empty(), if it couldn't be formatted.
    • formatNational

      Optional<String> formatNational(String number, @Nullable @Nullable String defaultRegion)
      Tries to format a phone number in national format. If not possible, Optional.empty() is returned. If country does not match param defaultRegion, international format is applied.
      Parameters:
      number - The phone number to format.
      defaultRegion - The default region (i.e. "CH" for switzerland).
      Returns:
      the formatted number or Optional.empty(), if it couldn't be formatted.
    • formatInternational

      Optional<String> formatInternational(String number, @Nullable @Nullable String defaultRegion)
      Tries to format a phone number in (readable) international format. If not possible, Optional.empty() is returned. You most probably want to use this format if it should be printed in any output or UI.
      Parameters:
      number - The phone number to format.
      Returns:
      the formatted number or Optional.empty(), if it couldn't be formatted.