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();
}
android 判斷EditText中輸入的值是數字、字母還是漢字的方法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.