Coder Social home page Coder Social logo

jaydroid1024 / phonetextwatcher Goto Github PK

View Code? Open in Web Editor NEW
32.0 1.0 5.0 11.17 MB

手机号3-4-4格式化输入监听器,支持自定义分隔符,支持末端输入/删除,中间输入/删除,任意位置黏贴/剪贴多个数字等多种交互场景。

Kotlin 8.83% Java 91.17%
textwatcher phonenumber

phonetextwatcher's Introduction

PhoneTextWatcher

手机号格式化监听器,支持普通输入/删除,中间输入/删除,在任意位置下黏贴/剪贴多个数字等多种交互场景。

目前支持的手机号格式为 3-4-4 分隔符可以自定义

Preview

video_phone_text_watcher

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' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.jaydroid1024:PhoneTextWatcher:0.0.2'
}

How to use

val editTextSpace = findViewById<EditText>(R.id.editText_space)
val textViewSpace = findViewById<TextView>(R.id.textView_space)
// 缺省分隔符为空格
val phoneTextWatcherSpace = PhoneTextWatcher()
editTextSpace.addTextChangedListener(phoneTextWatcherSpace)
// 设置格式化输入的回调
phoneTextWatcherSpace.setTextChangedCallback(object : TextChangeCallback() {
    override fun afterTextChanged(s: String?, isPhoneNumberValid: Boolean) {
        textViewSpace.text = "反格式化后的手机号为:$s \n是否是有效的手机号:$isPhoneNumberValid"
    }
})

val editTextLine = findViewById<EditText>(R.id.editText_line)
val textViewLine = findViewById<TextView>(R.id.textView_line)
// 指定分隔符为横线,或者你传入的字符
val phoneTextWatcherLine = PhoneTextWatcher(AsYouTypeFormatter.SEPARATOR_LINE)
editTextLine.addTextChangedListener(phoneTextWatcherLine)
// 设置格式化输入的回调
phoneTextWatcherLine.setTextChangedCallback(object : TextChangeCallback() {
    override fun afterTextChanged(s: String?, isPhoneNumberValid: Boolean) {
        textViewLine.text = "反格式化后的手机号为:$s \n是否是有效的手机号:$isPhoneNumberValid"
    }
})

How to work

//todo

Todo list

  • Change to SupperTextWatcher to handle bank card numberid card number
  • Support various formats of mobile phone number formatting input
  • Delete the separator and the previous number at the same time

Thanks

phonetextwatcher's People

Contributors

jaydroid1024 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.