Skip to content

Commit

Permalink
Limit Amount to 8 digits (#234)
Browse files Browse the repository at this point in the history
* Limit Amount to 8 digits

* Fix checkstyle

* Update user guide
  • Loading branch information
wltan authored Oct 29, 2020
1 parent e8a7ae5 commit 694932d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ This section aims to provide you with in-depth details on Fine\$\$e's unique fea

The formats of the parameters used in the rest of the document are as follows:
* `TITLE` and `CATEGORY` should consist of <abbr title="Alphanumeric characters, space, and the special characters !&quot;#$%&'()*+,-./:;&lt;=&gt;?@[\]^_`{\|}~">printable ASCII characters</abbr>, and cannot begin with a space.
* `AMOUNT`, `AMOUNT_FROM` and `AMOUNT_TO` should be non-negative numbers with 0 or 2 decimal places, with an optional `$` in front.
* `AMOUNT`, `AMOUNT_FROM` and `AMOUNT_TO` should be non-negative numbers up to 8 digits with 0 or 2 decimal places, with an optional `$` in front.
* `DATE`, `DATE_FROM` and `DATE_TO` should be in `dd/mm/yyyy` format, and cannot be later than the current date.
* `INDEX` should be a positive integer.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/
public class Amount implements Comparable<Amount> {

public static final String MESSAGE_CONSTRAINTS =
"Amounts should only contain non-negative numbers, with an optional 2 decimal places or '$' prefix";
public static final String VALIDATION_REGEX = "^\\$?\\d+(\\.\\d{2})?$";
public static final String MESSAGE_CONSTRAINTS = "Amounts should only contain non-negative numbers up to 8 digits,"
+ " with an optional 2 decimal places or '$' prefix";
public static final String VALIDATION_REGEX = "^\\$?\\d{1,8}(\\.\\d{2})?$";
private final BigDecimal value;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public void isValidAmount() {
assertTrue(Amount.isValidAmount("$3.50")); // $ prefix, 2 decimal places
assertTrue(Amount.isValidAmount("91")); // numbers
assertTrue(Amount.isValidAmount("911")); // numbers
assertTrue(Amount.isValidAmount("93121534")); // long numbers
assertTrue(Amount.isValidAmount("124293842033123")); // long numbers

// length tests
assertTrue(Amount.isValidAmount("93121534")); // 8 digits, valid
assertFalse(Amount.isValidAmount("931215344")); // 9 digits, invalid
assertFalse(Amount.isValidAmount("124293842033123")); // 15 digits, invalid
}

@Test
Expand Down

0 comments on commit 694932d

Please sign in to comment.