From 5b373b22e1e248246a101aceb2b99594e99da0b0 Mon Sep 17 00:00:00 2001 From: nixonwidjaja Date: Mon, 13 Nov 2023 20:42:45 +0800 Subject: [PATCH 1/2] Fix phone bug --- src/main/java/seedu/address/model/person/Phone.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index fe4687b0b56..d3b5e543eeb 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -31,12 +31,12 @@ public Phone(String phone) { * Returns true if a given string is a valid phone number. */ public static boolean isValidPhone(String test) { + if (test.charAt(0) == '+') { + test = test.substring(1); + } if (test.length() < 3 || test.length() > 20) { return false; } - if (test.charAt(0) == '+') { - return test.substring(1).matches(VALIDATION_REGEX); - } return test.matches(VALIDATION_REGEX); } From ac83f538cd46e0a8f6e8919dcf92e27cb39eb93c Mon Sep 17 00:00:00 2001 From: nixonwidjaja Date: Mon, 13 Nov 2023 20:46:31 +0800 Subject: [PATCH 2/2] Add constraint --- src/main/java/seedu/address/model/person/Phone.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index d3b5e543eeb..cb780ed4721 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -31,6 +31,9 @@ public Phone(String phone) { * Returns true if a given string is a valid phone number. */ public static boolean isValidPhone(String test) { + if (test.length() < 3) { + return false; + } if (test.charAt(0) == '+') { test = test.substring(1); }