final EditText et = (EditText) findViewById(R.id.et);
et.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
String phoneNum = editable.toString();
boolean b = isPhoneNumber(phoneNum);
if (b){
et.setTextColor(Color.rgb(0,255,0));
}else {
et.setTextColor(Color.rgb(255,0,0));
}
}
});
}
public boolean isPhoneNumber(String str){
String regex = "^((13[0-9])|(15[^4,\D])|(18[0,5-9]))\d{8}$";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
return m.find();
}