UMAR-MOBITSOLUTIONS UMAR-MOBITSOLUTIONS - 2 months ago 15
Android Question

How to create EditText accepts Alphabets only in android?

friends,

can any one guide me how can i enter only alphabets in EditText in android?

any help would be appriciated.

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

                }