Java Email Validate validateEmail(String email)

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

Description

Validates an email address.

License

Open Source License

Parameter

Parameter Description
email a parameter

Return

True if valid, false otherwise.

Declaration

public static boolean validateEmail(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  v a  2  s. c om*/
     * Validates an email address.
     * 
     * Taken from:
     * http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/
     * 
     * @param email
     * @return True if valid, false otherwise.
     */
    public static boolean validateEmail(String email) {
        if (email != null) {
            Pattern pattern = Pattern.compile(
                    "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
            return pattern.matcher(email).matches();
        } else {
            return false;
        }

    }
}

Related

  1. validateEmail(String email)
  2. validateEmail(String email)
  3. validateEmail(String email)
  4. validateEmail(String email)
  5. validateEmail(String email)
  6. validateEmail(String email)
  7. validateEmail(String email)
  8. validateEmail(String hex)
  9. validateEmail2(String field)