I need to validate the text field to input only text. No numeric or special characters allowed.
Asked
Active
Viewed 1,496 times
-1
-
in the XML, add this:... android:digits="abcdefghijklmnopqrstuvwxyz " – Jai Khambhayta May 19 '17 at 09:08
3 Answers
1
Try this one bro
android:digits=" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
set edittext property with capital and small

Ratilal Chopda
- 4,162
- 4
- 18
- 31
0
You can do it using regex, validate users input. Use the following function:
public boolean AlphaCheck(String name) {
return name.matches("[a-zA-Z]+");
}
Send the string(users input) to this function and if the input is valid it will return true and you can then proceed based on that.
Here is another way to do it
public boolean AlphaCheck(String name) {
char[] chars = name.toCharArray();
for (char c : chars) {
if(!Character.isLetter(c)) {
return false;
}
}
return true;
}

JBJ
- 288
- 2
- 13
0
You can create a filter for this
private String unwantedChars = "~#^|$%&*!1234567890";
private InputFilter filter = new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
if (source != null && unwantedChars.contains(("" + source))) {
return "";
}
return null;
}
};
editText.setFilters(new InputFilter[] { filter });

Dishonered
- 8,449
- 9
- 37
- 50