Skip to content

Instantly share code, notes, and snippets.

@AlexMisiulia
Created September 16, 2019 05:44
Show Gist options
  • Save AlexMisiulia/7216cecf49f517e66f75cb2de027232d to your computer and use it in GitHub Desktop.
Save AlexMisiulia/7216cecf49f517e66f75cb2de027232d to your computer and use it in GitHub Desktop.
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