19 package org.sleuthkit.datamodel;
21 import java.util.Arrays;
22 import java.util.HashSet;
24 import org.apache.commons.lang3.StringUtils;
34 private static final Set<String> TELEPHONY_CHARS =
new HashSet<>(Arrays.asList(
35 "-",
"(",
")",
"#",
"*",
","
38 private static final int MIN_PHONENUMBER_LEN = 3;
63 if (StringUtils.isEmpty(phoneNumber)) {
71 String normalizedNumber = phoneNumber.trim();
72 normalizedNumber = normalizedNumber.replaceAll(
"\\s+",
"");
73 normalizedNumber = normalizedNumber.replaceAll(
"[\\-()]",
"");
76 if (normalizedNumber.length() < MIN_PHONENUMBER_LEN) {
80 return normalizedNumber;
95 if (StringUtils.isEmpty(emailAddress)) {
103 return emailAddress.toLowerCase().trim();
124 return !StringUtils.isEmpty(accountUniqueID);
139 if (StringUtils.isEmpty(phoneNum)) {
143 String trimmedPhoneNum = phoneNum.trim();
147 for (
int i = 0; i < trimmedPhoneNum.length(); i++) {
148 if (!((trimmedPhoneNum.charAt(i) ==
'+' && i == 0)
149 || isValidPhoneChar(trimmedPhoneNum.charAt(i)))) {
164 private static boolean isValidPhoneChar(
char ch) {
165 return Character.isSpaceChar(ch)
166 || Character.isDigit(ch)
167 || TELEPHONY_CHARS.contains(String.valueOf(ch));
188 if (StringUtils.isEmpty(emailAddress)) {
192 if (emailAddress.contains(
"@") ==
false
193 || emailAddress.contains(
".") == false ) {
198 String[] tokens = emailAddress.split(
"@");
199 if (tokens.length < 2
200 || StringUtils.isEmpty(tokens[0])
201 || StringUtils.isEmpty(tokens[1])) {
206 String[] tokens2 = tokens[1].split(
"\\.");
207 return !(tokens2.length < 2
208 || StringUtils.isEmpty(tokens2[0])
209 || StringUtils.isEmpty(tokens2[1]));
static String normalizeEmailAddress(String emailAddress)
static boolean isValidPhoneNumber(String phoneNum)
static String normalizePhoneNum(String phoneNumber)
static final Account.Type PHONE
static boolean isValidEmailAddress(String emailAddress)
static boolean isValidAccountId(Account.Type accountType, String accountUniqueID)
static final Account.Type EMAIL