PhoneTextWatcher

Mobile phone number formatting listener, support ordinary input/delete, intermediate input/delete, in any position of the paste/clip multiple numbers and other interactive scenarios.

Currently supported mobile phone number format is 3-4-4 delimiter can be customized

Preview

How to get

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url 'https://jitpack.io'}}}Copy the code

Step 2. Add the dependency

dependencies {
    implementation 'com. Making. Jaydroid1024: PhoneTextWatcher: hundreds'
}
Copy the code

How to use

val editTextSpace = findViewById<EditText>(R.id.editText_space)
val textViewSpace = findViewById<TextView>(R.id.textView_space)
// The default delimiter is space
val phoneTextWatcherSpace = PhoneTextWatcher()
editTextSpace.addTextChangedListener(phoneTextWatcherSpace)
// Sets the callback for formatting input
phoneTextWatcherSpace.setTextChangedCallback(object : TextChangeCallback() {
    override fun afterTextChanged(s: String? , isPhoneNumberValid: Boolean) {
        textViewSpace.text = "$s \n Is a valid phone number: $isPhoneNumberValid"
    }
})

val editTextLine = findViewById<EditText>(R.id.editText_line)
val textViewLine = findViewById<TextView>(R.id.textView_line)
// Specify the delimiter as a line, or the character you pass in
val phoneTextWatcherLine = PhoneTextWatcher(AsYouTypeFormatter.SEPARATOR_LINE)
editTextLine.addTextChangedListener(phoneTextWatcherLine)
// Sets the callback for formatting input
phoneTextWatcherLine.setTextChangedCallback(object : TextChangeCallback() {
    override fun afterTextChanged(s: String? , isPhoneNumberValid: Boolean) {
        textViewLine.text = "$s \n Is a valid phone number: $isPhoneNumberValid"}})Copy the code

Go to

Github