This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Email.java
53 lines (43 loc) · 1.43 KB
/
Email.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package seedu.address.model.person;
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;
/**
* Represents a Person's phone number in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)}
*/
public class Email {
public static final String MESSAGE_EMAIL_CONSTRAINTS =
"Person emails should be 2 alphanumeric/period strings separated by '@'";
public static final String EMAIL_VALIDATION_REGEX = "[\\w\\.]+@[\\w\\.]+";
public final String value;
/**
* Constructs an {@code Email}.
*
* @param email A valid email address.
*/
public Email(String email) {
requireNonNull(email);
checkArgument(isValidEmail(email), MESSAGE_EMAIL_CONSTRAINTS);
this.value = email;
}
/**
* Returns if a given string is a valid person email.
*/
public static boolean isValidEmail(String test) {
return test.matches(EMAIL_VALIDATION_REGEX);
}
@Override
public String toString() {
return value;
}
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Email // instanceof handles nulls
&& this.value.equals(((Email) other).value)); // state check
}
@Override
public int hashCode() {
return value.hashCode();
}
}