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
  • 11,436
  • 3
  • 24
  • 35
Aftab Abbas
  • 45
  • 1
  • 9

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

            }