Skip to content

roma86/android_phone_number_formatter

Repository files navigation

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() });
...

About

Phone number formatter for Android EditText on the fly

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages