如何创建的EditText接受字母只能在Android的? [英] How to create EditText accepts Alphabets only in android?

查看:119
本文介绍了如何创建的EditText接受字母只能在Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

任何一个可以指导我的Andr​​ oid的EditText我怎么能只输入字母?

任何帮助将appriciated。

解决方案

 的EditText状态=(EditText上)findViewById(R.id.txtState);


                模式PS = Pattern.compile(^ [A-ZA-Z] + $);
                匹配毫秒= ps.matcher(state.getText()的toString());
                布尔BS = ms.matches();
                如果(BS == FALSE){
                    如果(ErrorMessage.contains(无效))
                        的ErrorMessage =的ErrorMessage +国家;
                    其他
                        的ErrorMessage =的ErrorMessage +无效状态;

                }
 

friends,

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

any help would be appriciated.

解决方案

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

                }

这篇关于如何创建的EditText接受字母只能在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆