文章內(nèi)容代碼來源于:http://www.cnblogs.com/jason-star/p/3316482.html
其它參考文章:https://my.oschina.net/u/1444624/blog/355337
核心代碼
String txt = edInput.getText().toString();
Pattern p = Pattern.compile("[0-9]*");
Matcher m = p.matcher(txt);
if(m.matches() ){
Toast.makeText(Main.this,"輸入的是數(shù)字", Toast.LENGTH_SHORT).show();
}
p=Pattern.compile("[a-zA-Z]");
m=p.matcher(txt);
if(m.matches()){
Toast.makeText(Main.this,"輸入的是字母", Toast.LENGTH_SHORT).show();
}
p=Pattern.compile("[\u4e00-\u9fa5]");
m=p.matcher(txt);
if(m.matches()){
Toast.makeText(Main.this,"輸入的是漢字", Toast.LENGTH_SHORT).show();
}