2

我如何在android中验证多个逗号(,)分隔的电子邮件ID。我正在使用下面的代码进行单个电子邮件验证。请任何人帮助我。

static boolean validEmail(String str_newEmail) {


         return str_newEmail.matches("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
        }

提前致谢。

4

3 回答 3

5

嗨,使用此代码,我认为这将对您有所帮助

String str_newEmail = "Bharath@in.com,bharath@appsforbb.co.in";
    String[] test = str_newEmail.split(",");
    for (int i = 0; i < test.length; i++) {
        if (!validEmail(test[i])) {
            System.out.println("This is not a vaild email");
            break;
        }
    }

电子邮件方法的验证。

    public boolean validEmail(String str_newEmail) {

    return str_newEmail.matches("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
            + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
}
于 2013-05-23T12:30:24.573 回答
1
private boolean isValidEmail(CharSequence target) {
    boolean emailflag = false;
    String emailArr[] = target.toString().split("[,]");
    for (int i = 0; i < emailArr.length; i++) {
        emailflag = android.util.Patterns.EMAIL_ADDRESS.matcher(
                emailArr[i].trim()).matches();
    }
    return emailflag;
}
于 2013-12-24T10:39:44.337 回答
0

您还可以使用 StringTokenizer:

String emails = "Bharath@in.com,bharath@appsforbb.co.in";
StringTokenizer st = new StringTokenizer(emails, ",");

while (st.hasMoreElements()) {
  String email = st.nextToken();
  if (!validEmail(email)) {
      System.out.println("Invalid email:" + email);
  }
}
于 2013-05-23T13:09:38.777 回答