Skip to content

Commit

Permalink
Merge pull request #277 from Sheeepen/master
Browse files Browse the repository at this point in the history
Update validation regex for name
  • Loading branch information
darrentfy authored Nov 13, 2023
2 parents 28316ca + 328b868 commit 0b8fddc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/student/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Name {
* The first character of the name must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "^[A-Za-z][A-Za-z ]{0,99}$";
public static final String VALIDATION_REGEX = "^(?=.{1,100}$)[A-Z][a-z]*([ ][A-Z][a-z]*)*\\s*$";

public final String value;

Expand Down Expand Up @@ -56,7 +56,7 @@ public boolean equals(Object other) {
}

Name otherName = (Name) other;
return value.toLowerCase().equals(otherName.value.toLowerCase());
return value.equals(otherName.value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public JsonAdaptedStudent(Student source) {
public Student toModelType() throws IllegalValueException {
final List<RiskLevel> studentRiskLevel = new ArrayList<>();


System.out.println(name);
if (name == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/model/student/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void isValidName() {

// valid names
// EP: one character alphabet only
assertTrue(Name.isValidName("a"));
assertTrue(Name.isValidName("A"));

// EP: Alphabetical characters with capital letters
assertTrue(Name.isValidName("Capital Tan"));
Expand Down
6 changes: 1 addition & 5 deletions src/test/java/seedu/address/model/student/StudentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ public void isSameStudent() {
editedAlice = new StudentBuilder(ALICE).withName(VALID_NAME_BOB).build();
assertFalse(ALICE.isSameStudent(editedAlice));

// name differs in case, all other attributes same -> returns true
Student editedBob = new StudentBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build();
assertTrue(BOB.isSameStudent(editedBob));

// name has trailing spaces, all other attributes same -> returns false
String nameWithTrailingSpaces = VALID_NAME_BOB + " ";
editedBob = new StudentBuilder(BOB).withName(nameWithTrailingSpaces).build();
Student editedBob = new StudentBuilder(BOB).withName(nameWithTrailingSpaces).build();
assertFalse(BOB.isSameStudent(editedBob));
}

Expand Down

0 comments on commit 0b8fddc

Please sign in to comment.