Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# PhoneNumberFormattingTextWatcher\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \nDeprecated in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nPhoneNumberFormattingTextWatcher\n================================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/telephony/PhoneNumberFormattingTextWatcher \"View this page in Java\") \n\n```\nopen class PhoneNumberFormattingTextWatcher : TextWatcher\n```\n\n|---|---------------------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.telephony.PhoneNumberFormattingTextWatcher](#) |\n\n*** ** * ** ***\n\n| **This class was deprecated in API level 35.**\n|\n| This is a thin wrapper on a \\`libphonenumber\\` \\`AsYouTypeFormatter\\`; it is recommended to use that instead.\n\nWatches a [android.widget.TextView](../widget/TextView.html#) and if a phone number is entered will format it.\n\nStop formatting when the user\n\n- Inputs non-dialable characters\n- Removes the separator in the middle of string.\n\nThe formatting will be restarted once the text is cleared.\n\nSummary\n-------\n\n| Public constructors ||\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [PhoneNumberFormattingTextWatcher](#PhoneNumberFormattingTextWatcher())`()` The formatting is based on the current system locale and future locale changes may not take effect on this instance. |\n| [PhoneNumberFormattingTextWatcher](#PhoneNumberFormattingTextWatcher(kotlin.String))`(`countryCode:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` The formatting is based on the given `countryCode`. |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [afterTextChanged](#afterTextChanged(android.text.Editable))`(`s:` `[Editable](../text/Editable.html#)!`)` \u003cbr /\u003e |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [beforeTextChanged](#beforeTextChanged(kotlin.CharSequence,%20kotlin.Int,%20kotlin.Int,%20kotlin.Int))`(`s:` `[CharSequence](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/index.html)!`, `start:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `count:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `after:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` \u003cbr /\u003e |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onTextChanged](#onTextChanged(kotlin.CharSequence,%20kotlin.Int,%20kotlin.Int,%20kotlin.Int))`(`s:` `[CharSequence](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char-sequence/index.html)!`, `start:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `before:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `count:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` \u003cbr /\u003e |\n\nPublic constructors\n-------------------\n\n### PhoneNumberFormattingTextWatcher\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nPhoneNumberFormattingTextWatcher()\n```\n\nThe formatting is based on the current system locale and future locale changes may not take effect on this instance. \n\n### PhoneNumberFormattingTextWatcher\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nPhoneNumberFormattingTextWatcher(countryCode: String!)\n```\n\nThe formatting is based on the given `countryCode`. \nThis method may take several seconds to complete, so it should only be called from a worker thread.\n\n| Parameters ||\n|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `countryCode` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: the ISO 3166-1 two-letter country code that indicates the country/region where the phone number is being entered. |\n\nPublic methods\n--------------\n\n### afterTextChanged\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun afterTextChanged(s: Editable!): Unit\n```\n\n**Deprecated:** *Deprecated in Java.* \n\n### beforeTextChanged\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun beforeTextChanged(\n s: CharSequence!, \n start: Int, \n count: Int, \n after: Int\n): Unit\n```\n\n**Deprecated:** *Deprecated in Java.* \n\n### onTextChanged\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun onTextChanged(\n s: CharSequence!, \n start: Int, \n before: Int, \n count: Int\n): Unit\n```\n\n**Deprecated:** *Deprecated in Java.*"]]