Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1.04 KB

README.md

File metadata and controls

41 lines (29 loc) · 1.04 KB

Android Phone Number Formatter

Format Android EditText content when it changed.

In case of PhoneNumberTextWatcher format is n nnn nnn nn nn

In case of PhoneNumberTextWatcher2 format is 8 (nnn) nnn nn nn

for othe formats see source and comments

USAGE:

...
import android.telephony.PhoneNumberFormattingTextWatcher;
import android.telephony.PhoneNumberUtils;
...
...
TextView phoneField = (TextView)findViewById(R.id.phoneField);
phoneField.addTextChangedListener(new PhoneNumberTextWatcher());
phoneField.setFilters(new InputFilter[] { new PhoneNumberFilter(), new InputFilter.LengthFilter(15) });
...

PhoneNumberTextWatcher2 with PhoneNumberFilter2

This variation include required prefix 8 ( and check max lenth inside TextWatcher, so InputFilter.LengthFilter is not used.

...
TextView phoneField = (TextView)findViewById(R.id.phoneField);
phoneField.addTextChangedListener(new PhoneNumberTextWatcher2());
phoneField.setFilters(new InputFilter[] { new PhoneNumberFilter2() });
...