Phone number formatting an EditText in Android

前端 未结 14 919
情深已故
情深已故 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条回答
  •  时光取名叫无心
    2020-12-02 12:21

    You can use a Regular Expression with pattern matching to extract number from a string.

        String s="";
        Pattern p = Pattern.compile("\\d+");
        Matcher m = p.matcher("(1111)123-456-789"); //editText.getText().toString()                                      
        while (m.find()) {
        s=s+m.group(0);
        }
        System.out.println("............"+s);    
    
        Output : ............1111123456789
    

提交回复
热议问题