In my EditText
I want to enter the first character as alpha and the remaining is whatever. I achieved this task with the help of TextWatcher
. But now my problem is if I entered something wrong(like digits, special characters) as my First character then my EditText
shouldn't accept the remaining characters. If I correct my first character then only my EditText
should accept. Is their any possibility to achieve this friends? If yes then please guide me friends.
My textWatcher code is
edittext.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
if (s.length() > 0) {
String str = edittext.getText().toString();
char t = str.charAt(0);
if (!Character.isLetter(t)) {
Toast.makeText(getApplicationContext(),
"please enter your first charecter as alpha",
Toast.LENGTH_LONG).show();
}
}
}
});
Thanks in advance.