Phone number formatting an EditText in Android

前端 未结 14 914
情深已故
情深已故 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:38

    If you're only interested in international numbers and you'd like to be able to show the flag of the country that matches the country code in the input, I wrote a small library for that:

    https://github.com/tfcporciuncula/phonemoji

    Here's how it looks:

    0 讨论(0)
  • 2020-12-02 12:40

    You can accept only numbers and phone number type using java code

     EditText number1 = (EditText) layout.findViewById(R.id.edittext); 
        number1.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_CLASS_PHONE);
         number1.setKeyListener(DigitsKeyListener.getInstance("0123456789”));
          number1.setFilters(new InputFilter[] {new InputFilter.LengthFilter(14)}); // 14 is max digits
    

    This code will avoid lot of validations after reading input

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