eunique0216 eunique0216 - 2 months ago 5
Android Question

Mask an EditText with Phone Number Format NaN like in PhoneNumberUtils

I want to make user inputted phone number in an editText to dynamically change format every time the user inputs a number. That is, when user inputs up to 4 digits, like 7144, the editText shows "714-4".
I would like the editText to be dynamically updated to format ###-###-#### whenever the user inputs a digit. how can this be done? also, I am handling more than one editTexts.


Easiest way to do this is to use the built in Android PhoneNumberFormattingTextWatcher.

So basically you get your EditText in code and set your text watcher like this..

EditText inputField = (EditText) findViewById(;
inputField.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

Nice think about using PhoneNumberFormattingTextWatcher is it will format your number entry correctly based on your locale.