Skip to content

Commit

Permalink
fix: payment validator not handling undefined monetary values
Browse files Browse the repository at this point in the history
  • Loading branch information
KenLSM committed Jul 10, 2023
1 parent ba3975f commit 6c58e4c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frontend/src/hooks/usePaymentFieldValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export const usePaymentFieldValidation = <

const amountValidation: RegisterOptions<T, V> = {
validate: (val) => {
if (val === '' && msgWhenEmpty) {
if (!val && msgWhenEmpty) {
return msgWhenEmpty
}

// Validate that it is a money value.
// Regex allows leading and trailing spaces, max 2dp
const validateMoney = /^\s*(\d+)(\.\d{0,2})?\s*$/.test(val ?? '')
Expand Down

0 comments on commit 6c58e4c

Please sign in to comment.