Java Email Validate isEmail(String data)

Here you can find the source of isEmail(String data)

Description

is Email

License

Open Source License

Return

boolean whether the String is a email address

Declaration

public static boolean isEmail(String data) 

Method Source Code


//package com.java2s;
import java.util.regex.*;

public class Main {
    public static final String REGEX_IS_EMAIL = "^[a-zA-Z0-9][a-zA-Z0-9_.]*@\\w+([.][a-zA-Z]+)+$";

    /**/*w  w  w .  j  a  va2s  .c  o  m*/
     * @return boolean whether the String is a email address
     */
    public static boolean isEmail(String data) {
        return isMatchRegex(data, REGEX_IS_EMAIL);
    }

    /**
     * 
     * @param data the String testing match the regex
     * @param regex    the String regex
     * @return whether the string match the regex
     */
    private static boolean isMatchRegex(String data, String regex) {
        Pattern p = Pattern.compile(regex);
        Matcher matcher = p.matcher(data);
        if (matcher.find()) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. isEmail(CharSequence input)
  2. isEmail(final String email)
  3. isEmail(final String s)
  4. isEmail(final String text)
  5. isEmail(String correo)
  6. isEmail(String email)
  7. isEmail(String email)
  8. isEmail(String email)
  9. isEmail(String email)