forked from AY2324S1-CS2103-F13-2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52321df
commit d2ad782
Showing
2 changed files
with
26 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,18 +14,20 @@ public class Email { | |
private static final String ALPHANUMERIC_NO_UNDERSCORE = "[^\\W_]+"; // alphanumeric characters except underscore | ||
private static final String LOCAL_PART_REGEX = "^" + ALPHANUMERIC_NO_UNDERSCORE + "([" + SPECIAL_CHARACTERS + "]" | ||
+ ALPHANUMERIC_NO_UNDERSCORE + ")*"; | ||
public static final String VALIDATION_REGEX = LOCAL_PART_REGEX + "@" + "([a-zA-Z]+\\.)+[a-zA-Z]{2,6}$"; | ||
|
||
public static final String MESSAGE_CONSTRAINTS = "Emails should be of the format local-part@domain " | ||
+ "and adhere to the following constraints:\n" | ||
+ "1. The local-part should only contain alphanumeric characters and these special characters, excluding " | ||
+ "the parentheses, (" + SPECIAL_CHARACTERS + "). The local-part may not start or end with any special " | ||
+ "characters.\n" | ||
+ "2. This is followed by a '@' and then a domain name. The domain name is made up of domain labels " | ||
private static final String DOMAIN_REGEX = ALPHANUMERIC_NO_UNDERSCORE + "([" + SPECIAL_CHARACTERS + "]" | ||
+ ALPHANUMERIC_NO_UNDERSCORE + ")*"; | ||
public static final String VALIDATION_REGEX = LOCAL_PART_REGEX + "@(" + DOMAIN_REGEX + "\\.)+[a-zA-Z]{2,6}$"; | ||
|
||
public static final String MESSAGE_CONSTRAINTS = "Emails should be of the format " | ||
+ "[email protected] and adhere to the following constraints:\n" | ||
+ "1. The local-part and domain should only contain alphanumeric characters and these special characters, " | ||
+ "excluding the parentheses, (" + SPECIAL_CHARACTERS + ").\n" | ||
+ "2. The local-part may not start or end with any special characters. Each special character cannot " | ||
+ "be next to each other.\n" | ||
+ "3. The local-part is followed by a '@' and a domain name. The domain name is made up of domain labels " | ||
+ "separated by periods.\n" | ||
+ "The domain name must:\n" | ||
+ " - end with a domain label that is between 2 to 6 characters (e.g. .com, .edu)\n" | ||
+ " - have each domain label start and end with characters only\n"; | ||
+ "4. Each domain label start and end with alphanumeric characters only.\n" | ||
+ "5. The top-level-domain should only contain 2 to 6 alphabet characters (e.g., .com, .edu).\n"; | ||
|
||
|
||
public final String value; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,6 @@ public void isValidEmail() { | |
|
||
// invalid parts | ||
assertFalse(Email.isValidEmail("peterjack@-")); // invalid domain name | ||
assertFalse(Email.isValidEmail("peterjack@exam_ple.com")); // underscore in domain name | ||
assertFalse(Email.isValidEmail("peter [email protected]")); // spaces in local part | ||
assertFalse(Email.isValidEmail("peterjack@exam ple.com")); // spaces in domain name | ||
assertFalse(Email.isValidEmail(" [email protected]")); // leading space | ||
|
@@ -54,8 +53,11 @@ public void isValidEmail() { | |
assertFalse(Email.isValidEmail("[email protected]")); // top level domain has less than two chars | ||
assertFalse(Email.isValidEmail("test@localhost")); // alphabets only | ||
assertFalse(Email.isValidEmail("123@145")); // numeric domain name | ||
assertFalse(Email.isValidEmail("[email protected]")); // mixture of alphanumeric and special characters | ||
assertFalse(Email.isValidEmail("[email protected]")); // domain name has symbols | ||
assertFalse(Email.isValidEmail("[email protected]")); | ||
assertFalse(Email.isValidEmail("[email protected]")); | ||
assertFalse(Email.isValidEmail("asdf@gmail_-s.com")); | ||
assertFalse(Email.isValidEmail("[email protected]")); | ||
assertFalse(Email.isValidEmail("[email protected]")); | ||
|
||
// valid email | ||
assertTrue(Email.isValidEmail("[email protected]")); // underscore in local part | ||
|
@@ -64,6 +66,14 @@ public void isValidEmail() { | |
assertTrue(Email.isValidEmail("[email protected]")); // hyphen in local part | ||
assertTrue(Email.isValidEmail("[email protected]")); // long local part | ||
assertTrue(Email.isValidEmail("[email protected]")); // more than one period in domain | ||
assertTrue(Email.isValidEmail("peterjack@exam_ple.com")); // underscore in domain name | ||
assertTrue(Email.isValidEmail("[email protected]")); // mixture of alphanumeric and special characters | ||
assertTrue(Email.isValidEmail("[email protected]")); // domain name has symbols | ||
assertTrue(Email.isValidEmail("[email protected]")); | ||
assertTrue(Email.isValidEmail("[email protected]")); | ||
assertTrue(Email.isValidEmail("asdf@mercedes_benz.com")); | ||
assertTrue(Email.isValidEmail("asdf_asdfasdf-asdfsFF@mercedes-benz_ccenz.com")); | ||
assertTrue(Email.isValidEmail("gg@gg+asedf_google.com")); | ||
} | ||
|
||
@Test | ||
|