Phone number formatting an EditText in Android

前端 未结 14 963
情深已故
情深已故 2020-12-02 12:03

I am making a simple Address Book app (targeting 4.2) that takes name, address, city, state, zip and phone.

I want to format the phone number input as a phone number

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 12:34

    Follow the instructions in this Answer to format the EditText mask.

    https://stackoverflow.com/a/34907607/1013929

    And after that, you can catch the original numbers from the masked string with:

    String phoneNumbers = maskedString.replaceAll("[^\\d]", "");
    

提交回复
热议问题