com.arch.util.EmailUtils Maven / Gradle / Ivy
package com.arch.util;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class EmailUtils {
private EmailUtils() {
}
public static boolean isValid(String email) {
// Pattern p = Pattern.compile("^[a-zA-Z]+(\\.[\\w-]+)*@([\\w-]+\\.)+[a-zA-Z]{2,7}$");
// Pattern p = Pattern.compile("^[A-Za-z]+[A-Za-z0-9._-]*@[A-Za-z0-9._-]+.[A-Za-z]{2,4}+(.[A-Za-z]{2})*$");
// Pattern p = Pattern.compile("^[_A-Za-z0-9-+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
Pattern p = Pattern.compile("^[A-Za-z0-9._-]*@[A-Za-z0-9._-]+.[A-Za-z]{2,4}+(.[A-Za-z]{2})*$");
Matcher m = p.matcher(email);
return m.find();
}
public static boolean isValidAndNotRequired(String email) {
if (email == null
|| email.isEmpty()) {
return true;
}
return !Arrays
.stream(email.split(";"))
.anyMatch(e -> !isValid(e));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy