0

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

Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
Aftab Abbas
  • 47
  • 1
  • 10

1 Answers1

1
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,";

            }