您的位置:首页 > 移动开发 > Android开发

android 判断EditText中输入的值是数字、字母还是汉字的方法

2013-10-10 16:44 671 查看
String text = edInput.getText().toString();

   Pattern p = Pattern.compile("[0-9]*"); 
     Matcher m = p.matcher(text); 
     if(m.matches() ){
      Toast.makeText(Main.this,"输入的是数字", Toast.LENGTH_SHORT).show();
      } 
     p=Pattern.compile("[a-zA-Z]");
     m=p.matcher(text);
     if(m.matches()){
      Toast.makeText(Main.this,"输入的是字母", Toast.LENGTH_SHORT).show();
     }
     p=Pattern.compile("[\u4e00-\u9fa5]");
     m=p.matcher(text);
     if(m.matches()){
      Toast.makeText(Main.this,"输入的是汉字", Toast.LENGTH_SHORT).show();
     }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: