Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/phone validator #202

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 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,10 @@ 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 8 digits long "
+ "according to Singapore mobile number format which starts with"
+ "8 or 9.";
public static final String VALIDATION_REGEX = "^[89]\\d{7}";
public final String value;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"metadata": "I like to play basketball."
}, {
"name" : "Elle Meyer",
"phone" : "9482224",
"phone" : "94822242",
"email" : "[email protected]",
"address" : "michegan ave",
"roles" : [ ],
Expand All @@ -68,7 +68,7 @@
"metadata": "I support Manchester United."
}, {
"name" : "Fiona Kunz",
"phone" : "9482427",
"phone" : "94824272",
"email" : "[email protected]",
"address" : "little tokyo",
"roles" : [ ],
Expand All @@ -81,7 +81,7 @@
"metadata": "I support Manchester United."
}, {
"name" : "George Best",
"phone" : "9482442",
"phone" : "94824422",
"email" : "[email protected]",
"address" : "4th street",
"roles" : [ ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ 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 = "88888888";
public static final String VALID_PHONE_BOB = "99999999";
public static final String VALID_EMAIL_AMY = "[email protected]";
public static final String VALID_EMAIL_BOB = "[email protected]";
public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1";
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_ROLE = "#friend";

private static final String VALID_NAME = "Rachel Walker";
private static final String VALID_PHONE = "123456";
private static final String VALID_PHONE = "87654321";
private static final String VALID_ADDRESS = "123 Main Street #0505";
private static final String VALID_EMAIL = "[email protected]";
private static final String VALID_ROLE_1 = "friend";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void test_nameDoesNotContainKeywords_returnsFalse() {
assertFalse(predicate.test(new PersonBuilder().withName("Alice Bob").build()));

// Keywords match phone, email and address, but does not match name
predicate = new NameContainsKeywordsPredicate(Arrays.asList("12345", "[email protected]", "Main", "Street"));
assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("12345")
predicate = new NameContainsKeywordsPredicate(Arrays.asList("87654321", "[email protected]", "Main", "Street"));
assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("87654321")
.withEmail("[email protected]").withAddress("Main Street").build()));
}

Expand Down
15 changes: 8 additions & 7 deletions src/test/java/seedu/address/model/person/PhoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@ public void isValidPhone() {
// invalid phone numbers
assertFalse(Phone.isValidPhone("")); // empty string
assertFalse(Phone.isValidPhone(" ")); // spaces only
assertFalse(Phone.isValidPhone("91")); // less than 3 numbers
assertFalse(Phone.isValidPhone("9190137")); // less than 8 numbers
assertFalse(Phone.isValidPhone("12345678")); // Does not start with 8 or 9
assertFalse(Phone.isValidPhone("phone")); // non-numeric
assertFalse(Phone.isValidPhone("9011p041")); // alphabets within digits
assertFalse(Phone.isValidPhone("9312 1534")); // spaces within digits
assertFalse(Phone.isValidPhone("17803682394326478")); // More than 8 number

// valid phone numbers
assertTrue(Phone.isValidPhone("911")); // exactly 3 numbers
assertTrue(Phone.isValidPhone("93121534"));
assertTrue(Phone.isValidPhone("124293842033123")); // long phone numbers
assertTrue(Phone.isValidPhone("87779381")); // exactly 8 numbers starting with 8 or 9
assertTrue(Phone.isValidPhone("93121534")); // exactly 8 numbers starting with 8 or 9
}

@Test
public void equals() {
Phone phone = new Phone("999");
Phone phone = new Phone("99171577");

// same values -> returns true
assertTrue(phone.equals(new Phone("999")));
assertTrue(phone.equals(new Phone("99171577")));

// same object -> returns true
assertTrue(phone.equals(phone));
Expand All @@ -55,6 +56,6 @@ public void equals() {
assertFalse(phone.equals(5.0f));

// different values -> returns false
assertFalse(phone.equals(new Phone("995")));
assertFalse(phone.equals(new Phone("99580770")));
}
}
10 changes: 5 additions & 5 deletions src/test/java/seedu/address/testutil/TypicalPersons.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ public class TypicalPersons {
.withAtt("0")
.withSess("1")
.withMetadata("I like to play basketball.").build();
public static final Person ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("9482224")
public static final Person ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("94822242")
.withEmail("[email protected]").withAddress("michegan ave").withMetadata("I support Manchester United.")
.build();
public static final Person FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("9482427")
public static final Person FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("94824272")
.withEmail("[email protected]").withAddress("little tokyo")
.withAmount("50.00")
.withAtt("0")
.withSess("1")
.withMetadata("I support Manchester United.").build();
public static final Person GEORGE = new PersonBuilder().withName("George Best").withPhone("9482442")
public static final Person GEORGE = new PersonBuilder().withName("George Best").withPhone("94824422")
.withEmail("[email protected]").withAddress("4th street").withMetadata("I support Manchester United.")
.build();

// Manually added
public static final Person HOON = new PersonBuilder().withName("Hoon Meier").withPhone("8482424")
public static final Person HOON = new PersonBuilder().withName("Hoon Meier").withPhone("84824242")
.withEmail("[email protected]").withAddress("little india").build();
public static final Person IDA = new PersonBuilder().withName("Ida Mueller").withPhone("8482131")
public static final Person IDA = new PersonBuilder().withName("Ida Mueller").withPhone("84821312")
.withEmail("[email protected]").withAddress("chicago ave").build();

// Manually added - Person's details found in {@code CommandTestUtil}
Expand Down
Loading