Format EditText view for phone numbers

后端 未结 8 1787
既然无缘
既然无缘 2020-12-28 20:49

I have an EditText view and I want it to format the user\'s input into the phone number format. For example, when the user types in 1234567890, the EditText view should dyna

相关标签:
8条回答
  • 2020-12-28 21:15

    I did a combination of things, i modified my input type to phone, then I used regex to remove all non numeric characters: phonenumber = phonenumber.replaceAll("\D", "");

    0 讨论(0)
  • 2020-12-28 21:15

    In your Java code you can use

    yourEditText.setInputType(InputTytpe.TYPE_CLASS_PHONE)

    or in your xml

    android:inputType="phone"

    Java

    XML

    0 讨论(0)
提交回复
热议问题