0

私のアプリケーションでは、フィールド名があります。フィールドに数字または .,?... 文字が含まれている場合は完全に機能しますが、usman(space)shafi と入力するとエラーが発生します。私のステートメントは、2 つの単語の間に無効な文字としてスペースを取ります。誰かがそれを機能させる方法を教えてください。ありがとう

ここにコードがあります

   if(!Pattern.matches("[a-zA-Z]+", textname.getText().toString().trim())){

         textname.setError("Invalid Characters");

     }
    // if(!Pattern.matches("[a-zA-Z]+", textkin.getText().toString().trim())){

  //     textkin.setError("Invalid Characters");

    // }");
4

3 に答える 3

0

この方法でこれを行います。あなたの問題は解決されます。

    String regex = "([A-Z a-z]+)";
    Pattern pattern1 = Pattern.compile(regex);
    Matcher matcher1 = pattern1.matcher(textname.getText().toString());

    if(!matcher1.matches()){
          textname.setError("Invalid Characters");
    }
于 2013-10-21T09:19:11.350 に答える