Java Email Validate isValidEmail(String email)

Here you can find the source of isValidEmail(String email)

Description

Test if a given email string is a valid E-mail address.

License

Open Source License

Parameter

Parameter Description
email E-mail address to validate.

Return

true if provided string is a valid E-mail address, false if not.

Declaration

public static boolean isValidEmail(String email) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.regex.Pattern;

public class Main {
    /**/*from   w ww .  j  a va  2 s . c  o m*/
     * Regular expression to validate E-mail string.
     */
    private static final Pattern EMAIL_PATTERN = Pattern
            .compile("^[_A-Za-z0-9-+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");

    /**
     * Test if a given <i>email</i> string is a valid E-mail address. The matching is based on RFC-5322 with some
     * extensions.
     *
     * @param email E-mail address to validate.
     * @return {@code true} if provided string is a valid E-mail address, {@code false} if not.
     */
    public static boolean isValidEmail(String email) {
        return email != null && EMAIL_PATTERN.matcher(email).matches();
    }
}

Related

  1. isMail(String email)
  2. isMobilesOrEmail(String str)
  3. isStrEmailAddress(String str)
  4. isValidEmail(final String email)
  5. isValidEmail(final String email)
  6. isValidEmail(String email)
  7. isValidEmail(String email)
  8. isValidEmail(String email)
  9. isValidEmail(String email)