From 0f19de4e0109a1749f146362dbc2a94de38fd157 Mon Sep 17 00:00:00 2001 From: Tan Yi Xian <> Date: Fri, 28 Oct 2022 04:02:42 +0800 Subject: [PATCH] Modify price validator to not accept 3.e1 --- .../foodrem/model/item/itemvalidators/ItemPriceValidator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/foodrem/model/item/itemvalidators/ItemPriceValidator.java b/src/main/java/seedu/foodrem/model/item/itemvalidators/ItemPriceValidator.java index a949e8c56aa..1a0bc803e76 100644 --- a/src/main/java/seedu/foodrem/model/item/itemvalidators/ItemPriceValidator.java +++ b/src/main/java/seedu/foodrem/model/item/itemvalidators/ItemPriceValidator.java @@ -30,9 +30,10 @@ static Void validateNumericString(String numericString, int maxDecimalPlace, int String messageNotANumber, String messageTooPrecise, String messageTooLarge, String messageIsNegative) { boolean isParsable = ValidationUtil.isParsableDouble(numericString); + boolean hasNoSpecialChars = numericString.matches("[0-9.-]*"); boolean isTooPrecise = ValidationUtil.isDoubleTooPrecise(numericString, maxDecimalPlace); - checkArgument(isParsable, messageNotANumber); + checkArgument(isParsable && hasNoSpecialChars, messageNotANumber); checkArgument(!isTooPrecise, messageTooPrecise); double number = Double.parseDouble(numericString);