Java Email Validate isValidEmailAddress(String emailAddress)

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

Description

is Valid Email Address

License

Open Source License

Declaration

public static boolean isValidEmailAddress(String emailAddress) 

Method Source Code

//package com.java2s;
/**//  w  w w . ja v  a 2s .c  o  m
 * Copyright (c) 2014-present Jonathan McCann
 *
 * This program 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 3 of the License, or (at your option) any later
 * version.
 *
 * This program 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.
 */

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

public class Main {
    private static final Pattern _emailAddressPattern = Pattern
            .compile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}"
                    + "[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}"
                    + "[a-zA-Z0-9])?)+$");

    public static boolean isValidEmailAddress(String emailAddress) {
        if (isNull(emailAddress)) {
            return false;
        }

        Matcher matcher = _emailAddressPattern.matcher(emailAddress);

        return matcher.matches();
    }

    public static boolean isNull(Object[] array) {
        if ((array == null) || (array.length == 0)) {
            return true;
        }

        for (Object o : array) {
            if (o == null) {
                return true;
            }
        }

        return false;
    }

    public static boolean isNull(String s) {
        if ((s == null) || s.isEmpty() || s.equalsIgnoreCase("null")) {
            return true;
        }

        return false;
    }
}

Related

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