Java Email Validate validateEmail(String email)

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

Description

Validates the syntax of the passed email.

License

Open Source License

Parameter

Parameter Description
email The email.

Return

True, if syntax ok.

Declaration

public static boolean validateEmail(String email) 

Method Source Code

//package com.java2s;
/*/*w  w  w . ja  v  a2s  .  c o m*/
 * ------------------------------------------------------------------------------
 * Hermes FTP Server
 * Copyright (c) 2005-2014 Lars Behnke
 * ------------------------------------------------------------------------------
 * 
 * This file is part of Hermes FTP Server.
 * 
 * Hermes FTP Server is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * Hermes FTP Server is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Hermes FTP Server; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * ------------------------------------------------------------------------------
 */

import java.util.regex.Pattern;

public class Main {
    /**
     * Validates the syntax of the passed email.
     * 
     * @param email The email.
     * @return True, if syntax ok.
     */
    public static boolean validateEmail(String email) {
        String patternStr = "^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@"
                + "[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
        return Pattern.matches(patternStr, email);
    }
}

Related

  1. isValidEmailAdress(String email)
  2. parseEmail(String target)
  3. validateEmail(String email)
  4. validateEmail(String email)
  5. validateEmail(String email)
  6. validateEmail(String email)
  7. validateEmail(String email)
  8. validateEmail(String email)
  9. validateEmail(String email)