1. 程式人生 > >android判斷EditText輸入的數字、中文還是字母方法

android判斷EditText輸入的數字、中文還是字母方法

String txt = edInput.getText().toString();

 Pattern p = Pattern.compile("[0-9]*");  Matcher m = p.matcher(txt);  if(m.matches() ){
 
 Toast.makeText(Main.this,"輸入的是數字", 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();
 
 }