Created
September 16, 2019 05:44
-
-
Save AlexMisiulia/7216cecf49f517e66f75cb2de027232d 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
private fun getCountryIsoCode(number: String): String? { | |
val validatedNumber = if (number.startsWith("+")) number else "+$number" | |
val phoneNumber = try { | |
phoneNumberUtil.parse(validatedNumber, null) | |
} catch (e: NumberParseException) { | |
Log.e(TAG, "error during parsing a number") | |
null | |
} | |
if(phoneNumber == null) return null | |
return phoneNumberUtil.getRegionCodeForCountryCode(phoneNumber.countryCode) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment