Java Email Validate isEmail(String str, boolean nullCheck)

Here you can find the source of isEmail(String str, boolean nullCheck)

Description

is Email

License

Apache License

Declaration

public static boolean isEmail(String str, boolean nullCheck) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static boolean isEmail(String str, boolean nullCheck) {
        String checkPattern = "^([A-Za-z0-9_\\-\\.'])+@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,6})$";

        if (nullCheck == false || isRequired(str)) {
            return isRegex(str, checkPattern, nullCheck);
        } else {//ww  w .j  ava2  s  .com
            return false;
        }
    }

    public static boolean isRequired(String str) {
        if (str == null || str.trim().length() == 0) {
            return false;
        }

        return true;
    }

    public static boolean isRegex(String str, String regex) {
        return isRegex(str, regex, false);
    }

    public static boolean isRegex(String str, String regex, boolean nullCheck) {
        if (nullCheck == false || isRequired(str)) {
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(str);

            return matcher.matches();
        } else {
            return false;
        }
    }
}

Related

  1. isEmail(String str)
  2. isEmail(String str)
  3. isEmail(String str)
  4. isEmail(String str)
  5. isEmail(String str)
  6. isEmail(String string)
  7. isEmail(String string)
  8. isEmail(String text)
  9. isEmail(String val)