Android Email String Validate validateEmail(String aEmailAddress)

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

Description

Validate email according rules of eXo cloud

License

Open Source License

Declaration

public static boolean validateEmail(String aEmailAddress) 

Method Source Code

//package com.java2s;
/*// ww  w . jav  a2 s  . c om
 * Copyright (C) 2003-2014 eXo Platform SAS.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

public class Main {
    /**
     * Validate email according rules of eXo cloud
     */
    public static boolean validateEmail(String aEmailAddress) {
        if (aEmailAddress == null)
            return false;
        boolean result = true;
        if (!hasNameAndDomain(aEmailAddress)) {
            result = false;
        }
        return result;
    }

    /**
     * Check whether the email has username and domain
     *
     * @param aEmailAddress
     * @return
     */
    private static boolean hasNameAndDomain(String aEmailAddress) {
        String[] tokens = aEmailAddress.split("@");
        return tokens.length == 2 && tokens[0].trim().length() > 0
                && tokens[1].trim().length() > 3
                && tokens[1].split("\\.").length > 1
                && tokens[1].split("\\.")[1].length() > 1;
    }
}

Related

  1. checkMail(String email)
  2. isEmail(String s)
  3. isValidEmail(String email)
  4. isValidEmail(CharSequence target)
  5. emailValidator(final String mailAddress)
  6. validateEmail(final String email)