Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static boolean isEmail(String email) {
        if (isEmpty(email, true))
            return false;
        Pattern pattern = Pattern.compile("^([a-z]|[A-Z]|[0-9])+@([a-z]|[A-Z]|[0-9])+\\.([a-z]|[A-Z]){2,}$");
        Matcher matcher = pattern.matcher(email.trim());
        return matcher.matches();
    }

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

    public static boolean isEmpty(String str, boolean isTrim) {
        if (str == null)
            return true;
        if (isTrim) {
            return "".equals(str.trim());
        } else {
            return "".equals(str);
        }
    }

    public static boolean isEmpty(String... params) {

        return isEmpty(false, params);
    }

    public static boolean isEmpty(boolean isTrim, String... params) {

        if (params == null || params.length == 0)
            return true;
        for (String param : params) {
            if (isEmpty(param, isTrim))
                return true;
        }
        return false;
    }
}