Skip to content

Commit

Permalink
Merge pull request #51 from enhao25/branch-update-phone-validation
Browse files Browse the repository at this point in the history
Update phone validation to follow singapore format
  • Loading branch information
samleewy authored Mar 14, 2021
2 parents 8196d51 + 237af51 commit 544f710
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/model/student/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public class Phone {


public static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be at least 3 digits long";
public static final String VALIDATION_REGEX = "\\d{3,}";
"Phone numbers should only contain numbers, and it should be exactly 8 digits long with "
+ "starting value of 6, 8 or 9";
public static final String VALIDATION_REGEX = "[6|8|9]\\d{7}$";
public final String value;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@
"relationship" : "Father"
}, {
"name" : "Elle Meyer",
"phone" : "9482224",
"phone" : "94822242",
"email" : "werner@example.com",
"address" : "michegan ave",
"studyLevel" : "Primary 2",
"guardianPhone" : "92134012",
"relationship" : "Mother"
}, {
"name" : "Fiona Kunz",
"phone" : "9482427",
"phone" : "94824272",
"email" : "lydia@example.com",
"address" : "little tokyo",
"studyLevel" : "Sec 2",
"guardianPhone" : "99021234",
"relationship" : "Mother"
}, {
"name" : "George Best",
"phone" : "9482442",
"phone" : "94824422",
"email" : "anna@example.com",
"address" : "4th street",
"studyLevel" : "Sec 3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ public class CommandTestUtil {

public static final String VALID_NAME_AMY = "Amy Bee";
public static final String VALID_NAME_BOB = "Bob Choo";
public static final String VALID_PHONE_AMY = "11111111";
public static final String VALID_PHONE_BOB = "22222222";
public static final String VALID_PHONE_AMY = "83501122";
public static final String VALID_PHONE_BOB = "65420011";
public static final String VALID_EMAIL_AMY = "amy@example.com";
public static final String VALID_EMAIL_BOB = "bob@example.com";
public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1";
public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3";
public static final String VALID_STUDY_LEVEL_AMY = "Sec 5";
public static final String VALID_STUDY_LEVEL_BOB = "Primary 2";
public static final String VALID_GUARDIAN_PHONE_AMY = "33333333";
public static final String VALID_GUARDIAN_PHONE_BOB = "44444444";
public static final String VALID_GUARDIAN_PHONE_AMY = "90112344";
public static final String VALID_GUARDIAN_PHONE_BOB = "98102211";
public static final String VALID_RELATIONSHIP_AMY = "Mother";
public static final String VALID_RELATIONSHIP_BOB = "Father";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void test_nameDoesNotContainKeywords_returnsFalse() {

// Keywords match phone, email and address, but does not match name
predicate = new NameContainsKeywordsPredicate(Arrays.asList("12345", "alice@email.com", "Main", "Street"));
assertFalse(predicate.test(new StudentBuilder().withName("Alice").withPhone("12345")
assertFalse(predicate.test(new StudentBuilder().withName("Alice").withPhone("81111111")
.withEmail("alice@email.com").withAddress("Main Street").build()));
}
}
11 changes: 8 additions & 3 deletions src/test/java/seedu/address/model/student/PhoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ public void isValidPhone() {
assertFalse(Phone.isValidPhone("phone")); // non-numeric
assertFalse(Phone.isValidPhone("9011p041")); // alphabets within digits
assertFalse(Phone.isValidPhone("9312 1534")); // spaces within digits
assertFalse(Phone.isValidPhone("73121534")); // wrong first digit
assertFalse(Phone.isValidPhone("124293842033123")); // long phone numbers
assertFalse(Phone.isValidPhone("624293842033123")); // long phone numbers with starting 6
assertFalse(Phone.isValidPhone("824293842033123")); // long phone numbers with starting 8
assertFalse(Phone.isValidPhone("924293842033123")); // long phone numbers with starting 9

// valid phone numbers
assertTrue(Phone.isValidPhone("911")); // exactly 3 numbers
assertTrue(Phone.isValidPhone("93121534"));
assertTrue(Phone.isValidPhone("124293842033123")); // long phone numbers
assertTrue(Phone.isValidPhone("63121534")); // exactly 8 numbers with starting 6
assertTrue(Phone.isValidPhone("81121534")); // exactly 8 numbers with starting 8
assertTrue(Phone.isValidPhone("91120093")); // exactly 8 numbers with starting 9
}
}
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/testutil/StudentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
public class StudentBuilder {

public static final String DEFAULT_NAME = "Amy Bee";
public static final String DEFAULT_PHONE = "85355255";
public static final String DEFAULT_PHONE = "83501122";
public static final String DEFAULT_EMAIL = "amy@gmail.com";
public static final String DEFAULT_ADDRESS = "Blk 136 Jurong West Ave 6, #08-111";
public static final String DEFAULT_STUDY_LEVEL = "Secondary 5";
public static final String DEFAULT_GUARDIAN_PHONE = "91234567";
public static final String DEFAULT_GUARDIAN_PHONE = "90112344";
public static final String DEFAULT_RELATIONSHIP = "Mother";

private Name name;
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/seedu/address/testutil/TypicalStudents.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ public class TypicalStudents {
.withEmail("cornelia@example.com").withAddress("10th street")
.withStudyLevel("Junior College 2").withGuardianPhone("97213021").withRelationship("Father")
.build();
public static final Student ELLE = new StudentBuilder().withName("Elle Meyer").withPhone("9482224")
public static final Student ELLE = new StudentBuilder().withName("Elle Meyer").withPhone("94822242")
.withEmail("werner@example.com").withAddress("michegan ave")
.withStudyLevel("Primary 2").withGuardianPhone("92134012").withRelationship("Mother")
.build();
public static final Student FIONA = new StudentBuilder().withName("Fiona Kunz").withPhone("9482427")
public static final Student FIONA = new StudentBuilder().withName("Fiona Kunz").withPhone("94824272")
.withEmail("lydia@example.com").withAddress("little tokyo")
.withStudyLevel("Sec 2").withGuardianPhone("99021234").withRelationship("Mother")
.build();
public static final Student GEORGE = new StudentBuilder().withName("George Best").withPhone("9482442")
public static final Student GEORGE = new StudentBuilder().withName("George Best").withPhone("94824422")
.withEmail("anna@example.com").withAddress("4th street")
.withStudyLevel("Sec 3").withGuardianPhone("87620000").withRelationship("Father")
.build();

// Manually added
public static final Student HOON = new StudentBuilder().withName("Hoon Meier").withPhone("8482424")
public static final Student HOON = new StudentBuilder().withName("Hoon Meier").withPhone("84824242")
.withEmail("stefan@example.com").withAddress("little india")
.withStudyLevel("Secondary 4").withGuardianPhone("98110022").withRelationship("Father").build();
public static final Student IDA = new StudentBuilder().withName("Ida Mueller").withPhone("8482131")
public static final Student IDA = new StudentBuilder().withName("Ida Mueller").withPhone("84821312")
.withEmail("hans@example.com").withAddress("chicago ave")
.withStudyLevel("JC 4").withGuardianPhone("87621200").withRelationship("Uncle").build();

Expand Down

0 comments on commit 544f710

Please sign in to comment.