EditText define addTextChangedListener
editReceiver_No.addTextChangedListener(new MyTextWatcher(this, editReceiver_No));
copy the below class MyTextWatcher
public class MyTextWatcher implements TextWatcher {
EditText editTextMessage;
Context context;
public MyTextWatcher(Context context, EditText editTextMessage) {
this.editTextMessage = editTextMessage;
this.context = context;
}
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void afterTextChanged(Editable s) {
boolean isEnglish = true;
for (char c : s.toString().toCharArray()) {
if (Character.UnicodeBlock.of(c) != Character.UnicodeBlock.BASIC_LATIN) {
isEnglish = false;
break;
}
}
if (isEnglish) {
Log.e("==>>", "ture");
} else {
try {
Utils.showOtherLanguageAddAlertDialog(context, "", "You can only enter english character");
editTextMessage.getText().delete(editTextMessage.getText().length() - 1, editTextMessage.getText().length());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
above code is checking only English charaters are types or not