Created
December 16, 2021 16:23
-
-
Save Oleur/96c96540b1f0cb34ad50ceef46b0d1ad to your computer and use it in GitHub Desktop.
Format Phone Number while typing with libphonenumber library
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 val countryCode: String = Locale.getDefault().country | |
private val phoneNumberFormatter = PhoneNumberUtil.getInstance().getAsYouTypeFormatter(countryCode) | |
private fun getFormattedNumber(lastNonSeparator: Char, hasCursor: Boolean): String? { | |
return if (hasCursor) { | |
phoneNumberFormatter.inputDigitAndRememberPosition(lastNonSeparator) | |
} else { | |
phoneNumberFormatter.inputDigit(lastNonSeparator) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment