Skip to content

Commit c6838b6

Browse files
Allow credit invoices (#1)
This change allows negative amounts to be reported
1 parent 736ec4e commit c6838b6

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

basicvalidators.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// Helper function to validate if the string is a valid currency format (with 2 decimal places)
1414
func IsValidCurrencyFormat(amount string) bool {
1515
// Regex pattern to match valid decimal with exactly two decimal places
16-
validCurrency := regexp.MustCompile(`^\d+(\.\d{2})$`)
16+
validCurrency := regexp.MustCompile(`^-?\d+(\.\d{2})$`)
1717
return validCurrency.MatchString(amount)
1818
}
1919

basicvalidators_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,27 @@ func TestCheckCurrency(t *testing.T) {
4646

4747
// Test an invalid currency
4848
if IsValidCurrencyFormat("abc") {
49-
t.Fatalf("Expected currency 100 to be invalid")
49+
t.Fatalf("Expected currency abc to be invalid")
5050
}
5151

5252
// Test an invalid currency
5353
if IsValidCurrencyFormat("abc.fg") {
54-
t.Fatalf("Expected currency 100 to be invalid")
54+
t.Fatalf("Expected currency abc.fg to be invalid")
5555
}
5656

5757
// Test an invalid currency
5858
if IsValidCurrencyFormat("abc.23") {
59-
t.Fatalf("Expected currency 100 to be invalid")
59+
t.Fatalf("Expected currency abc.23 to be invalid")
6060
}
6161

6262
// Test an invalid currency
6363
if IsValidCurrencyFormat("100.ab") {
64-
t.Fatalf("Expected currency 100 to be invalid")
64+
t.Fatalf("Expected currency 100.ab to be invalid")
6565
}
6666

6767
// Test negative currency
68-
if IsValidCurrencyFormat("-100.00") {
69-
t.Fatalf("Expected currency 100 to be invalid")
68+
if !IsValidCurrencyFormat("-100.00") {
69+
t.Fatalf("Expected currency -100.00 to be valid")
7070
}
7171

7272
//Test zero

0 commit comments

Comments
 (0)