diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/RegexUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/RegexUtils.java index ae90e4ea5e4051fe23fdf119b4ca98bd5562b09b..624a93511c5b6f6f0d5f5481c62c5c4868e61da5 100644 --- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/RegexUtils.java +++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/RegexUtils.java @@ -40,6 +40,54 @@ public final class RegexUtils { return isMatch(RegexConstants.REGEX_MOBILE_SIMPLE, input); } + + /** + * Returns the domain part of a given Email address + * + * @param email The Email address. E.g Returns "protonmail.com" from the given Email "johnsmith@protonmail.com". + * @return the domain part of a given Email address. + */ + public static String extractEmailProvider(String email) { + return email.substring(email.lastIndexOf("@") + 1); + } + + /** + * Returns the username part of a given Email address. E.g. Returns "johnsmith" from the given Email "johnsmith@protonmail.com". + * + * @param email The Email address. + * @return the username part of a given Email address. + */ + public static String extractEmailUsername(String email) { + return email.substring(0, email.lastIndexOf("@")); + } + + + /** + * Return whether a given Email address is on a specified Email provider. E.g. "johnsmith@protonmail.com" and "gmail.com" will return false. + * + * @param email The Email address. + * @param emailProvider The Email provider to testify against. + * @return {@code true}: yes
{@code false}: no + */ + public static boolean isFromEmailProvider(String email, String emailProvider) { + return extractEmailProvider(email).equalsIgnoreCase(emailProvider); + } + + /** + * Return whether a given Email address is on any of the specified Email providers list (array). E.g. Useful if you pass it a list of real Email provider services and check if the Email is a disposable Email or a real one. + * + * @param email The Email address. + * @param emailProviders The list of Email providers to testify against. + * @return {@code true}: yes
{@code false}: no + */ + public static boolean isFromAnyOfEmailProviders(String email, String[] emailProviders) { + return com.blankj.utilcode.util.ArrayUtils.contains(emailProviders, extractEmailProvider(email)); + } + + + + + /** * Return whether input matches regex of exact mobile. *