Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2223S2#82 from SHni99/v1.3
Browse files Browse the repository at this point in the history
[v1.3] Set character limits to input variables
  • Loading branch information
hongshenggg authored Mar 30, 2023
2 parents fa48dc7 + 418a00c commit 81a4875
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
31 changes: 16 additions & 15 deletions src/main/java/seedu/address/model/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ public class Email {

private static final String SPECIAL_CHARACTERS = "+_.-";
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 "
+ "separated by periods.\n"
+ "The domain name must:\n"
+ " - end with a domain label at least 2 characters long\n"
+ " - have each domain label start and end with alphanumeric characters\n"
+ " - have each domain label consist of alphanumeric characters, separated only by hyphens, if any.";
+ "and adhere to the following constraints:\n"
+ "1. The local-part should only contain alphanumeric characters (limit at 1 to 20 chars) 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 "
+ "separated by periods.\n"
+ "The domain name must:\n"
+ " - end with a domain label at least 2 characters long\n"
+ " - have each domain label start and end with alphanumeric characters\n"
+ " - have each domain label consist of alphanumeric characters, separated only by hyphens, if any.";
// alphanumeric and special characters
private static final String ALPHANUMERIC_NO_UNDERSCORE = "[^\\W_]+"; // alphanumeric characters except underscore
private static final String ALPHANUMERIC_NO_UNDERSCORE = "[^\\W_]{1,20}";
private static final String LOCAL_PART_REGEX = "^" + ALPHANUMERIC_NO_UNDERSCORE + "([" + SPECIAL_CHARACTERS + "]"
+ ALPHANUMERIC_NO_UNDERSCORE + ")*";
+ ALPHANUMERIC_NO_UNDERSCORE + ")*";
private static final String DOMAIN_PART_REGEX = ALPHANUMERIC_NO_UNDERSCORE
+ "(-" + ALPHANUMERIC_NO_UNDERSCORE + ")*";
+ "(-" + ALPHANUMERIC_NO_UNDERSCORE + ")*";
private static final String DOMAIN_LAST_PART_REGEX = "(" + DOMAIN_PART_REGEX + "){2,}$"; // At least two chars
private static final String DOMAIN_REGEX = "(" + DOMAIN_PART_REGEX + "\\.)*" + DOMAIN_LAST_PART_REGEX;
public static final String VALIDATION_REGEX = LOCAL_PART_REGEX + "@" + DOMAIN_REGEX;
Expand Down Expand Up @@ -59,8 +60,8 @@ public String toString() {
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Email // instanceof handles nulls
&& value.equals(((Email) other).value)); // state check
|| (other instanceof Email // instanceof handles nulls
&& value.equals(((Email) other).value)); // state check
}

@Override
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/seedu/address/model/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
public class Name {

public static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank. ";

public static final String MESSAGE_LEN_CONSTRAINTS = "Names should be between 1-20 characters long";
"Names should only contain alphanumeric characters and spaces, and it should not be blank "
+ "and should be between 1-24 characters long";

/*
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]{1,24}";

public final String fullName;

Expand All @@ -30,7 +29,6 @@ public class Name {
public Name(String name) {
requireNonNull(name);
checkArgument(isValidName(name), MESSAGE_CONSTRAINTS);
// checkArgument(isValidLength(name), "Names should be between 1-20 characters long");
fullName = name;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class Phone {


public static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be at least 8-15 digits long";
public static final String VALIDATION_REGEX = "\\d{3,}";
"Phone numbers should only contain numbers, and it should be at least 3-15 digits long";
public static final String VALIDATION_REGEX = "\\d{3,15}";
public final String value;

/**
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/model/person/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
public class Status {

public static final String MESSAGE_CONSTRAINTS =
"Status should only contain alphanumeric characters, numbers and spaces, and it should not be blank";
"Status should only contain alphanumeric characters, numbers and spaces, and it should not be blank. "
+ "Max characters: 20";

/*
* The first character denotes the year of the student and must not be a whitespace,
* while the second character denotes the course of the student and must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]{1,30}";

public final String fullStatusDetail;

Expand Down Expand Up @@ -48,8 +49,8 @@ public String toString() {
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Status // instanceof handles nulls
&& fullStatusDetail.equals(((Status) other).fullStatusDetail)); // state check
|| (other instanceof Status // instanceof handles nulls
&& fullStatusDetail.equals(((Status) other).fullStatusDetail)); // state check
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ParserUtilTest {
private static final String INVALID_TAG = "#friend";

private static final String VALID_NAME = "Rachel Walker";
private static final String VALID_PHONE = "123456";
private static final String VALID_PHONE = "1234567";
private static final String VALID_ADDRESS = "123 Main Street #0505";
private static final String VALID_EMAIL = "[email protected]";
private static final String VALID_TAG_1 = "friend";
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/model/person/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public void isValidName() {
assertTrue(Name.isValidName("12345")); // numbers only
assertTrue(Name.isValidName("peter the 2nd")); // alphanumeric characters
assertTrue(Name.isValidName("Capital Tan")); // with capital letters
assertTrue(Name.isValidName("David Roger Jackson Ray Jr 2nd")); // long names
assertTrue(Name.isValidName("David Roger Jack Jr 2nd")); // long names
}
}

0 comments on commit 81a4875

Please sign in to comment.