Java Email Validate isValidEmail(final String email)

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

Description

Validate the format of a user entered email

License

Open Source License

Parameter

Parameter Description
email email entered by the user

Return

true if the email is in good format

Declaration

public static boolean isValidEmail(final String email) 

Method Source Code

//package com.java2s;
/**//  w  w w .  j  a  va2  s  .  co m
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    static Pattern pattern = Pattern.compile(
            "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$",
            Pattern.CASE_INSENSITIVE);

    /**
     * Validate the format of a user entered email
     *
     * @param email email entered by the user
     * @return true if the email is in good format
     */
    public static boolean isValidEmail(final String email) {
        final Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }
}

Related

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