Last active
September 13, 2021 09:21
-
-
Save rahulsainani/c8df05b83bfe87a54bc350a155117ce0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PhoneNumberFormatter @Inject constructor( | |
private val phoneNumberUtil: PhoneNumberUtil | |
) { | |
fun formatToCountryCodeAndNationalNumber(phoneNumberWithCountryCode: String): Pair<Int, Long>? = | |
try { | |
// Can pass a default country code as the second param if there is one or an empty string if not | |
val number = phoneNumberUtil.parse(phoneNumberWithCountryCode, "") | |
Pair(number.countryCode, number.nationalNumber) | |
} catch (e: NumberParseException) { | |
Timber.e(e, "Error getting country code and national number") | |
null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment