Skip to content

Commit

Permalink
Validate phone numbers starting with + as valid
Browse files Browse the repository at this point in the history
  • Loading branch information
zxjtan committed Aug 29, 2018
1 parent dde2751 commit 10b3589
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
3 changes: 1 addition & 2 deletions src/seedu/addressbook/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -1058,8 +1058,7 @@ private static boolean isPersonNameValid(String name) {
* @param phone to be validated
*/
private static boolean isPersonPhoneValid(String phone) {
return phone.matches("\\d+"); // phone nonempty sequence of digits
//TODO: implement a more permissive validation
return phone.matches("\\+?\\d+"); // phone is nonempty sequence of digits that can start with a +
}

/**
Expand Down
57 changes: 32 additions & 25 deletions test/expected.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
|| ===================================================
|| ===================================================
|| AddessBook Level 1 - Version 1.0
|| AddressBook Level 1 - Version 1.0
|| Welcome to your Address Book!
|| ===================================================
|| The given file name [ ] is not a valid file name!
Expand All @@ -9,7 +9,7 @@
|| ===================================================
|| ===================================================
|| ===================================================
|| AddessBook Level 1 - Version 1.0
|| AddressBook Level 1 - Version 1.0
|| Welcome to your Address Book!
|| ===================================================
|| The given file name [directoryThatDoesNotExist/valid.filename] is not a valid file name!
Expand All @@ -18,7 +18,7 @@
|| ===================================================
|| ===================================================
|| ===================================================
|| AddessBook Level 1 - Version 1.0
|| AddressBook Level 1 - Version 1.0
|| Welcome to your Address Book!
|| ===================================================
|| The given file name [.noFilename] is not a valid file name!
Expand All @@ -27,7 +27,7 @@
|| ===================================================
|| ===================================================
|| ===================================================
|| AddessBook Level 1 - Version 1.0
|| AddressBook Level 1 - Version 1.0
|| Welcome to your Address Book!
|| ===================================================
|| The given file name [data/notRegularFile.txt] is not a valid file name!
Expand All @@ -36,7 +36,7 @@
|| ===================================================
|| ===================================================
|| ===================================================
|| AddessBook Level 1 - Version 1.0
|| AddressBook Level 1 - Version 1.0
|| Welcome to your Address Book!
|| ===================================================
|| Enter command: || [Command entered:exit]
Expand All @@ -45,7 +45,7 @@
|| ===================================================
|| ===================================================
|| ===================================================
|| AddessBook Level 1 - Version 1.0
|| AddressBook Level 1 - Version 1.0
|| Welcome to your Address Book!
|| ===================================================
|| Using default storage file : addressbook.txt
Expand Down Expand Up @@ -121,6 +121,13 @@
|| Example: add John Doe p/98765432 e/[email protected]
||
|| ===================================================
|| Enter command: || [Command entered: add Valid Name p/1+2345 e/[email protected]]
|| Invalid command format: add
|| add: Adds a person to the address book.
|| Parameters: NAME p/PHONE_NUMBER e/EMAIL
|| Example: add John Doe p/98765432 e/[email protected]
||
|| ===================================================
|| Enter command: || [Command entered: add Adam Brown p/111111 e/[email protected]]
|| New person added: Adam Brown, Phone: 111111, Email: [email protected]
|| ===================================================
Expand All @@ -129,12 +136,12 @@
||
|| 1 persons found!
|| ===================================================
|| Enter command: || [Command entered: add Betsy Choo p/222222 e/[email protected]]
|| New person added: Betsy Choo, Phone: 222222, Email: [email protected]
|| Enter command: || [Command entered: add Betsy Choo p/+222222 e/[email protected]]
|| New person added: Betsy Choo, Phone: +222222, Email: [email protected]
|| ===================================================
|| Enter command: || [Command entered: list]
|| 1. Adam Brown Phone Number: 111111 Email: [email protected]
|| 2. Betsy Choo Phone Number: 222222 Email: [email protected]
|| 2. Betsy Choo Phone Number: +222222 Email: [email protected]
||
|| 2 persons found!
|| ===================================================
Expand All @@ -143,19 +150,19 @@
|| ===================================================
|| Enter command: || [Command entered: list]
|| 1. Adam Brown Phone Number: 111111 Email: [email protected]
|| 2. Betsy Choo Phone Number: 222222 Email: [email protected]
|| 2. Betsy Choo Phone Number: +222222 Email: [email protected]
|| 3. Charlie Dickson Phone Number: 333333 Email: [email protected]
||
|| 3 persons found!
|| ===================================================
|| Enter command: || [Command entered: add Dickson Ee e/[email protected] p/444444]
|| New person added: Dickson Ee, Phone: 444444, Email: [email protected]
|| Enter command: || [Command entered: add Dickson Ee e/[email protected] p/+444444]
|| New person added: Dickson Ee, Phone: +444444, Email: [email protected]
|| ===================================================
|| Enter command: || [Command entered: list]
|| 1. Adam Brown Phone Number: 111111 Email: [email protected]
|| 2. Betsy Choo Phone Number: 222222 Email: [email protected]
|| 2. Betsy Choo Phone Number: +222222 Email: [email protected]
|| 3. Charlie Dickson Phone Number: 333333 Email: [email protected]
|| 4. Dickson Ee Phone Number: 444444 Email: [email protected]
|| 4. Dickson Ee Phone Number: +444444 Email: [email protected]
||
|| 4 persons found!
|| ===================================================
Expand All @@ -164,9 +171,9 @@
|| ===================================================
|| Enter command: || [Command entered: list]
|| 1. Adam Brown Phone Number: 111111 Email: [email protected]
|| 2. Betsy Choo Phone Number: 222222 Email: [email protected]
|| 2. Betsy Choo Phone Number: +222222 Email: [email protected]
|| 3. Charlie Dickson Phone Number: 333333 Email: [email protected]
|| 4. Dickson Ee Phone Number: 444444 Email: [email protected]
|| 4. Dickson Ee Phone Number: +444444 Email: [email protected]
|| 5. Esther Potato Phone Number: 555555 Email: [email protected]
||
|| 5 persons found!
Expand All @@ -188,18 +195,18 @@
|| 0 persons found!
|| ===================================================
|| Enter command: || [Command entered: find Betsy]
|| 1. Betsy Choo Phone Number: 222222 Email: [email protected]
|| 1. Betsy Choo Phone Number: +222222 Email: [email protected]
||
|| 1 persons found!
|| ===================================================
|| Enter command: || [Command entered: find Dickson]
|| 1. Charlie Dickson Phone Number: 333333 Email: [email protected]
|| 2. Dickson Ee Phone Number: 444444 Email: [email protected]
|| 2. Dickson Ee Phone Number: +444444 Email: [email protected]
||
|| 2 persons found!
|| ===================================================
|| Enter command: || [Command entered: find Charlie Betsy]
|| 1. Betsy Choo Phone Number: 222222 Email: [email protected]
|| 1. Betsy Choo Phone Number: +222222 Email: [email protected]
|| 2. Charlie Dickson Phone Number: 333333 Email: [email protected]
||
|| 2 persons found!
Expand Down Expand Up @@ -243,8 +250,8 @@
|| ===================================================
|| Enter command: || [Command entered: list]
|| 1. Adam Brown Phone Number: 111111 Email: [email protected]
|| 2. Betsy Choo Phone Number: 222222 Email: [email protected]
|| 3. Dickson Ee Phone Number: 444444 Email: [email protected]
|| 2. Betsy Choo Phone Number: +222222 Email: [email protected]
|| 3. Dickson Ee Phone Number: +444444 Email: [email protected]
|| 4. Esther Potato Phone Number: 555555 Email: [email protected]
||
|| 4 persons found!
Expand All @@ -254,17 +261,17 @@
|| ===================================================
|| Enter command: || [Command entered: list]
|| 1. Adam Brown Phone Number: 111111 Email: [email protected]
|| 2. Betsy Choo Phone Number: 222222 Email: [email protected]
|| 3. Dickson Ee Phone Number: 444444 Email: [email protected]
|| 2. Betsy Choo Phone Number: +222222 Email: [email protected]
|| 3. Dickson Ee Phone Number: +444444 Email: [email protected]
||
|| 3 persons found!
|| ===================================================
|| Enter command: || [Command entered: delete 1]
|| Deleted Person: Adam Brown Phone Number: 111111 Email: [email protected]
|| ===================================================
|| Enter command: || [Command entered: list]
|| 1. Betsy Choo Phone Number: 222222 Email: [email protected]
|| 2. Dickson Ee Phone Number: 444444 Email: [email protected]
|| 1. Betsy Choo Phone Number: +222222 Email: [email protected]
|| 2. Dickson Ee Phone Number: +444444 Email: [email protected]
||
|| 2 persons found!
|| ===================================================
Expand Down
7 changes: 4 additions & 3 deletions test/input.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
list

##########################################################
# test add person command, setup state for futuer tests
# test add person command, setup state for future tests
##########################################################

# should catch invalid args format
Expand All @@ -26,17 +26,18 @@
add []\[;] p/12345 e/[email protected]
add Valid Name p/not_numbers e/[email protected]
add Valid Name p/12345 e/notAnEmail
add Valid Name p/1+2345 e/[email protected]

# should add correctly
add Adam Brown p/111111 e/[email protected]
list
add Betsy Choo p/222222 e/[email protected]
add Betsy Choo p/+222222 e/[email protected]
list

# order of phone and email should not matter
add Charlie Dickson e/[email protected] p/333333
list
add Dickson Ee e/[email protected] p/444444
add Dickson Ee e/[email protected] p/+444444
list
add Esther Potato p/555555 e/[email protected]
list
Expand Down

0 comments on commit 10b3589

Please sign in to comment.