String str = "234电饭锅";
//判断输入的为数字
Pattern pattern = Pattern.compile("[0-9]*");
Matcher matcher = pattern .matcher(str);
if(matcher .matches() ){
Toast.makeText(Main.this,"输入的是数字", Toast.LENGTH_SHORT).show();
}
//判断输入的为字母
Pattern pattern =Pattern.compile("[a-zA-Z]");
Matcher matcher = pattern .matcher(str);
if(matcher .matches()){
Toast.makeText(Main.this,"输入的是字母", Toast.LENGTH_SHORT).show();
}
//判断输入的为汉字
Pattern pattern =Pattern.compile("[\u4e00-\u9fa5]");
Matcher matcher = pattern .matcher(str);
if(matcher .matches()){
Toast.makeText(Main.this,"输入的是汉字", Toast.LENGTH_SHORT).show();
}
更多好内容戳下面: