You are creating two different objects of listener while removing or adding.
mPassword.removeTextChangedListener(new InputValidator(mPassword));
phone = mPassword.getText().toString();
phone = formatPhoneNumber(phone);
Log.i("PHONE", "Phone NUMB IS:"+phone);
mPassword.setText(phone);
flag = false;
mPassword.addTextChangedListener(new InputValidator(mPassword));
This must be
Add members as
private InputValidator mPasswordTextWatcher = null;
private InputValidator mUserNameTextWatcher = null;
in onCreate()
mPasswordTextWatcher = new InputValidator(mPassword);
mUserNameTextWatcher = new InputValidator(mUsername);
// Called when user type in EditText
mUsername.addTextChangedListener(mUserNameTextWatcher);
mPassword.addTextChangedListener(mPasswordTextWatcher);
and do it now as
mPassword.removeTextChangedListener(mPasswordTextWatcher);
phone = mPassword.getText().toString();
phone = formatPhoneNumber(phone);
Log.i("PHONE", "Phone NUMB IS:"+phone);
mPassword.setText(phone);
flag = false;
mPassword.addTextChangedListener(mPasswordTextWatcher);
Do same for username EditText.