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

Update phone parsing #172

Merged
19 changes: 14 additions & 5 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ Format: `add n/NAME p/PHONE_NUMBER [e/EMAIL] [a/ADDRESS] [t/TAG]…​ [d/DATE_O

Examples:
* `add n/John Doe p/98765432 e/[email protected] a/John street, block 123, #01-01 d/02-01-2024`
* `add n/Betsy Crowe t/friend e/[email protected] a/Newgate Prison p/12345678 t/criminal d/03-28-2024`
* `add p/12345678 n/Jane Smith d/01-01-2024 ec/98765432`
* `add p/12345678 n/Jane Smith d/01-01-2024`
* `add n/Betsy Crowe t/friend e/[email protected] a/Newgate Prison p/62345678 t/criminal d/03-28-2024`
* `add p/92345678 n/Jane Smith d/01-01-2024 ec/98765432`
* `add p/92345678 n/Jane Smith d/01-01-2024`

### Listing all persons : `list`

Expand Down Expand Up @@ -147,7 +147,7 @@ Finds contacts whose names or/and phone numbers or/and address contain any of th
Format: `find [n/NAMEKEYWORDS] [p/PHONEKEYWORDS] [a/ADDRESSKEYWORDS]`

**NOTE:** At least one field MUST be provided
e.g. `find n/Hans` or `find p/12345678` or `find a/wall street` will work
e.g. `find n/Hans` or `find p/82345678` or `find a/wall street` will work
e.g. `find Hans` or `find wall street` or `find` will fail
* The search is case-insensitive. e.g `hans` will match `Hans` or `wall Street` will match `Wall Street`
* The order of the keywords does not matter. e.g. `Hans Bo` will match `Bo Hans`
Expand Down Expand Up @@ -244,6 +244,15 @@ _Details coming soon ..._

--------------------------------------------------------------------------------------------------------------------

## Contact field requirements

### Phone
* Phone numbers can only contain 8 numbers, and must begin with a 6, 8, or 9.
* Spaces in the middle of a phone number are accepted (eg. 9123 4523), as are phone numbers without spaces (eg. 91234523).
* Spaces in unusual locations will render the phone number invalid (eg. 912 34523).

--------------------------------------------------------------------------------------------------------------------

## FAQ

**Q**: How do I transfer my data to another Computer?<br>
Expand All @@ -262,7 +271,7 @@ _Details coming soon ..._

Action | Format, Examples
-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------
**Add** | `add n/NAME p/PHONE_NUMBER [e/EMAIL] [a/ADDRESS] [t/TAG]…​ [d/DATE_OF_LAST_VISIT] [ec/EMERGENCY_CONTACT]` <br> e.g., `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 1234665 t/friend t/colleague d/07-23-2024`
**Add** | `add n/NAME p/PHONE_NUMBER [e/EMAIL] [a/ADDRESS] [t/TAG]…​ [d/DATE_OF_LAST_VISIT] [ec/EMERGENCY_CONTACT]` <br> e.g., `add n/James Ho p/82224444 e/[email protected] a/123, Clementi Rd, 1234665 t/friend t/colleague d/07-23-2024`
**Clear** | `clear`
**Delete** | `delete INDEX`<br> e.g., `delete 3`
**Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…​ [d/DATE_OF_LAST_VISIT]`<br> e.g.,`edit 2 n/James Lee e/[email protected]`
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/seedu/address/model/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@
*/
public class Phone {


public static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be exactly 8 digits long.";
public static final String VALIDATION_REGEX = "\\d{8}";
"Phone numbers must have exactly 8 numbers, and no letters or symbols. \n"
+ "They can only begin with 6, 8, or 9.";

/**
* This validation regex checks that the first character in the phone number is either a 6, 8, or 9.
* Since {@code SocialBook} is meant only for use in Singapore, restricting it to the
* possible phone numbers helps users catch possible typos.
* After the first character, there must be 3 more numbers,
* followed by any number of whitespaces before 4 more numbers.
* This comes out to 8 numbers in total, with any number of whitespaces separating the phone
* number into 2 halves of 4 numbers each. Some software displays phone numbers
* this way, so we want to support parsing of this phone number format too.
*/
public static final String VALIDATION_REGEX = "[689]\\d{3}\\s*\\d{4}";
public final String value;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class CommandTestUtil {

public static final String VALID_NAME_AMY = "Amy Bee";
public static final String VALID_NAME_BOB = "Bob Choo-Choo";
public static final String VALID_PHONE_AMY = "11111111";
public static final String VALID_PHONE_BOB = "22222222";
public static final String VALID_PHONE_AMY = "8888\t8888";
public static final String VALID_PHONE_BOB = "69281029";
public static final String VALID_EMAIL_AMY = "[email protected]";
public static final String VALID_EMAIL_BOB = "[email protected]";
public static final String VALID_EMERGENCY_CONTACT_AMY = VALID_PHONE_AMY;
Expand Down Expand Up @@ -71,7 +71,7 @@ public class CommandTestUtil {

// whitespace-only names are invalid
public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + " ";
// 'a' not allowed in phones, emergency contacts
// 'a' not allowed in phones or emergency contacts
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a";
public static final String INVALID_EMERGENCY_CONTACT_DESC = " " + PREFIX_EMERGENCY_CONTACT + "911a";
// missing '@' symbol
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/logic/parser/ParserUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class ParserUtilTest {
private static final String NO_ENTRY = "";

private static final String VALID_NAME = "Rachel Walker-Runner";
private static final String VALID_PHONE = "12345678";
private static final String VALID_PHONE = "92345678";
private static final String VALID_ADDRESS = "123 Main Street #0505";
private static final String VALID_EMAIL = "[email protected]";
private static final String VALID_EMERGENCY_CONTACT = "12345678";
private static final String VALID_EMERGENCY_CONTACT = "62345678";
private static final String VALID_TAG_1 = "friend";
private static final String VALID_TAG_2 = "neighbour";
private static final String VALID_DATEOFLASTVISIT = "02-02-2024";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void test_addressDoesNotContainKeywords_returnsFalse() {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ public void isValidEmergencyContact() {

// invalid emergency contacts
assertFalse(EmergencyContact.isValidEmergencyContact("")); // empty string
assertFalse(EmergencyContact.isValidEmergencyContact(" ")); // spaces only
assertFalse(EmergencyContact.isValidEmergencyContact(" \t\n ")); // whitespaces only
assertFalse(EmergencyContact.isValidEmergencyContact("phone")); // non-numeric
assertFalse(EmergencyContact.isValidEmergencyContact("9011p041")); // alphabets within digits
assertFalse(EmergencyContact.isValidEmergencyContact("9312 1534")); // spaces within digits
assertFalse(EmergencyContact.isValidEmergencyContact("1234")); // not 8 digits long
assertFalse(EmergencyContact.isValidEmergencyContact("123456789")); // not 8 digits long
assertFalse(EmergencyContact.isValidEmergencyContact("9234")); // less than 8 digits
assertFalse(EmergencyContact.isValidEmergencyContact("623456789")); // more than 8 digits
assertFalse(EmergencyContact.isValidEmergencyContact("82345 678")); // whitespace in weird place
assertFalse(EmergencyContact.isValidEmergencyContact("00000000")); // does not start with 6, 8, or 9
assertFalse(EmergencyContact.isValidEmergencyContact("7918 2933")); // does not start with 6, 8, or 9

// valid emergency contacts
assertTrue(EmergencyContact.isValidEmergencyContact("00000000")); // exactly 8 zeros
assertTrue(EmergencyContact.isValidEmergencyContact("93121534")); // normal-looking mobile number
assertTrue(EmergencyContact.isValidEmergencyContact("62429384")); // normal-looking landline number
assertTrue(EmergencyContact.isValidEmergencyContact("9312 1534")); // spaces within digits
assertTrue(EmergencyContact.isValidEmergencyContact("8234 3234")); // multiple spaces within number
assertTrue(EmergencyContact.isValidEmergencyContact("9992\t2933")); // tab within number
}

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

// 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("12345678")
assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("92345678")
.withEmail("[email protected]").withAddress("Main Street").build()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ public void equals() {
public void test_phoneContainsKeywords_returnsTrue() {
// One keyword
PhoneContainsKeywordsPredicate predicate =
new PhoneContainsKeywordsPredicate(Collections.singletonList("12345678"));
assertTrue(predicate.test(new PersonBuilder().withPhone("12345678").build()));
new PhoneContainsKeywordsPredicate(Collections.singletonList("92345678"));
assertTrue(predicate.test(new PersonBuilder().withPhone("92345678").build()));

// Multiple keywords
predicate = new PhoneContainsKeywordsPredicate(Arrays.asList("1234", "5678"));
assertTrue(predicate.test(new PersonBuilder().withPhone("12345678").build()));
predicate = new PhoneContainsKeywordsPredicate(Arrays.asList("9234", "5678"));
assertTrue(predicate.test(new PersonBuilder().withPhone("92345678").build()));

// Only one matching keyword
predicate = new PhoneContainsKeywordsPredicate(Arrays.asList("1234", "5678"));
assertTrue(predicate.test(new PersonBuilder().withPhone("12349876").build()));
predicate = new PhoneContainsKeywordsPredicate(Arrays.asList("9234", "5678"));
assertTrue(predicate.test(new PersonBuilder().withPhone("92349876").build()));
}

@Test
public void test_phoneDoesNotContainKeywords_returnsFalse() {
// Zero keywords
PhoneContainsKeywordsPredicate predicate = new PhoneContainsKeywordsPredicate(Collections.emptyList());
assertFalse(predicate.test(new PersonBuilder().withPhone("12345678").build()));
assertFalse(predicate.test(new PersonBuilder().withPhone("82345678").build()));

// Non-matching keyword
predicate = new PhoneContainsKeywordsPredicate(Arrays.asList("7899"));
assertFalse(predicate.test(new PersonBuilder().withPhone("12345678").build()));
assertFalse(predicate.test(new PersonBuilder().withPhone("82345678").build()));

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

Expand Down
15 changes: 9 additions & 6 deletions src/test/java/seedu/address/model/person/PhoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ public void isValidPhone() {

// invalid phone numbers
assertFalse(Phone.isValidPhone("")); // empty string
assertFalse(Phone.isValidPhone(" ")); // spaces only
assertFalse(Phone.isValidPhone("91")); // not 8 digits long
assertFalse(Phone.isValidPhone(" \t\n ")); // whitespaces only
assertFalse(Phone.isValidPhone("phone")); // non-numeric
assertFalse(Phone.isValidPhone("9011p041")); // alphabets within digits
assertFalse(Phone.isValidPhone("9312 1534")); // spaces within digits
assertFalse(Phone.isValidPhone("1234")); // not 8 digits long
assertFalse(Phone.isValidPhone("123456789")); // not 8 digits long
assertFalse(Phone.isValidPhone("9234")); // less than 8 digits
assertFalse(Phone.isValidPhone("623456789")); // more than 8 digits
assertFalse(Phone.isValidPhone("82345 678")); // whitespace not separating phone number into halves
assertFalse(Phone.isValidPhone("00000000")); // does not start with 6, 8, or 9
assertFalse(Phone.isValidPhone("7918 2933")); // does not start with 6, 8, or 9

// valid phone numbers
assertTrue(Phone.isValidPhone("00000000")); // exactly 8 zeros
assertTrue(Phone.isValidPhone("93121534")); // normal-looking mobile number
assertTrue(Phone.isValidPhone("62429384")); // normal-looking landline number
assertTrue(Phone.isValidPhone("9312 1534")); // one space between digits
assertTrue(Phone.isValidPhone("9001 2003")); // multiple spaces between digits
assertTrue(Phone.isValidPhone("9123\t4567")); // tab between digits
}

@Test
Expand Down