edittext_解释

时间:2023-03-08 15:58:30

============ 2   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();
     }

==== 1 Android EditText 限制输入数字和字母设置

在xml:EditText 设置属性----
android:digis="ABCDE555555&&&&&"
ABCDE555555&&&&&"是你的限制规则。
例如:android:digits="0123456789abcdefghigklmnopqrstuvwxyz"
规则是只能输入英文字母(小写)和数字