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中输入的值是数字、字母还是汉字的方法
时间:2024-3-2 17:30 作者:韩俊 分类: Android
标签: android