I have an EditText field in my project which stands for the full name of the person.So I want only letters and spaces to be allowed in it.So I tried the following in the
Please put space between like below string, it working code.
android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ "
Try this:
EditText yourEditText = (EditText) findViewById(R.id.yourEditText);
yourEditText.setFilters(new InputFilter[] {
new InputFilter() {
@Override
public CharSequence filter(CharSequence cs, int start,
int end, Spanned spanned, int dStart, int dEnd) {
// TODO Auto-generated method stub
if(cs.equals("")){ // for backspace
return cs;
}
if(cs.toString().matches("[a-zA-Z ]+")){
return cs;
}
return "";
}
}
});
this worked for me (whitespace in the middle, not at the end) android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Try this
android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Put space in between your strings. If you put space at the end of a string it will be automatically trimmed off.
I have used space after ending of small letters and starting of capital letters
use regex.. pattern should be
Full_Name_Pattern = "[A-Z][a-z]+( [A-Z][a-z]+)*";
Below change worked for me:-
android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Put space in between your strings. If you put space at the end of a string it will get trimmed off automatically.
I have used space after ending of small letters and starting with capital letters.