Package ch.tocco.nice2.toolbox.api.phone
Interface PhoneFormatter
- All Known Implementing Classes:
PhoneFormatterImpl
public interface PhoneFormatter
-
Method Summary
Modifier and TypeMethodDescriptionformatE164
(String number, @Nullable String defaultRegion) Tries to format a phone number in E.164 format.formatInternational
(String number, @Nullable String defaultRegion) Tries to format a phone number in (readable) international format.formatNational
(String number, @Nullable String defaultRegion) Tries to format a phone number in national format.
-
Method Details
-
formatE164
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
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
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.
-