Java Email Validate isValidEmail(String emailAddress)

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

Description

This method is used to test whether a string is a valid email address or not

License

Open Source License

Parameter

Parameter Description
emailAddress the input string for test

Return

if the email address is valid return true,otherwise return false.

Declaration

public static boolean isValidEmail(String emailAddress) 

Method Source Code


//package com.java2s;
/*/*from  w w w . ja  va  2  s . co m*/
* Copyright (c) 2007 IJO Technologies Ltd.
* www.ijotechnologies.com
* All rights reserved.
*
* This software is the confidential and proprietary information of
* IJO Technologies ("Confidential Information").
* You shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement you
* entered into with IJO Technologies.
*/

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

public class Main {
    private static final String EMAIL_REGULAR_EXPRESSION = "^[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";

    /**
     * This method is used to test whether a string is a valid email address or not
     *
     * @param emailAddress the input string for test
     * @return if the email address is valid return true,otherwise return false.
     */
    public static boolean isValidEmail(String emailAddress) {
        if (emailAddress == null) {
            return false;
        }

        Pattern p = Pattern.compile(EMAIL_REGULAR_EXPRESSION);
        Matcher m = p.matcher(emailAddress);
        return m.matches();
    }
}

Related

  1. isValidEmail(String email)
  2. isValidEmail(String email)
  3. isValidEmail(String email)
  4. isValidEmail(String email)
  5. isValidEmail(String email)
  6. isValidEmail(String eMailAddress)
  7. IsValidEmail(String input)
  8. isValidEmailAddr(String str)
  9. isValidEmailAddress(String addr)