Reputation: 57
I am validating an EditText
and want to restrict input to [a-z][A-z] and a space.
For instance
Aftab Abbs
Not sure how to proceed, is there a way to achieve this?
Thanks
Upvotes: 0
Views: 98
Reputation: 66
EditText state = (EditText) findViewById(R.id.txtState);
Pattern ps = Pattern.compile("^[a-zA-Z ]+$");
Matcher ms = ps.matcher(state.getText().toString());
boolean bs = ms.matches();
if (bs == false) {
if (ErrorMessage.contains("invalid"))
ErrorMessage = ErrorMessage + "state,";
else
ErrorMessage = ErrorMessage + "invalid state,";
}
Upvotes: 1