Java Email Validate validateEmail(String email)

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

Description

Checks if given email is valid by matching it to regex pattern.

License

Apache License

Parameter

Parameter Description
email <code>String</code> value of email

Return

boolean type value true if email is correct, false if not

Declaration

public static boolean validateEmail(String email) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.regex.Pattern;

public class Main {
    /**//from   w  w  w.java 2s .co m
     * Checks if given email is valid by matching it to regex pattern.
     *
     * @param email <code>String</code> value of email
     * @return <code>boolean</code> type value true if email is correct, false if not
     */
    public static boolean validateEmail(String email) {
        final Pattern pattern = Pattern.compile("^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$");
        if (!pattern.matcher(email).matches()) {
            return false;
        }
        return true;
    }
}

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 hex)
  8. validateEmail2(String field)
  9. validateEmailAddress(String address)