Commit ebc64cd
authored
Added 4 useful methods
/**
* 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<br>{@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<br>{@code false}: no
*/
public static boolean isFromAnyOfEmailProviders(String email, String[] emailProviders) {
return com.blankj.utilcode.util.ArrayUtils.contains(emailProviders, extractEmailProvider(email));
}1 parent 66a4c04 commit ebc64cd
File tree
1 file changed
+48
-0
lines changed- lib/utilcode/src/main/java/com/blankj/utilcode/util
1 file changed
+48
-0
lines changedLines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
43 | 91 | | |
44 | 92 | | |
45 | 93 | | |
| |||
0 commit comments