Android检查char数组中的数字

时间:2017-02-06 22:00:13

标签: java android arrays

我有以下命令,我试图转换。如何将此命令转换为Java并在Android上运行?

textBox2.Text.ToCharArray().Any(c => Char.IsDigit(c))

1 个答案:

答案 0 :(得分:1)

TextView textBox2 = (TextView) findViewById(R.id.textBox2);
Pattern ps = Pattern.compile("^[a-zA-Z ]+$");
            Matcher ms = ps.matcher(textBox2.getText().toString());
            boolean bs = ms.matches();
            if (bs == false) {
                //fail
                             } 
             else{
                //success  
                  }

替代方法:您可以从TextView的XML文件中执行此操作

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

请根据您的需要进行测试和编辑。但我们的想法是根据您的需要使用正则表达式