diff --git a/frontend/src/routes/account/+page.svelte b/frontend/src/routes/account/+page.svelte index ba73ade..e75cd3d 100644 --- a/frontend/src/routes/account/+page.svelte +++ b/frontend/src/routes/account/+page.svelte @@ -192,6 +192,26 @@ let buyingGiftCard = $state(false); let purchaseResultCode = $state(null); + // Derived validations for Buy Gift Card form + let isBuyExpiryValid = $derived( + /^\d{2}\/\d{2}$/.test(buyNewCardExpiry) && + (() => { + const [monthStr, yearStr] = buyNewCardExpiry.split('/'); + const month = parseInt(monthStr, 10); + const year = 2000 + parseInt(yearStr, 10); + if (month < 1 || month > 12) return false; + const expiryDate = new SvelteDate(year, month); + return expiryDate >= new SvelteDate(); + })() + ); + + let isBuyCardValid = $derived( + buySelectedCard !== '' || + (isValidLuhn(buyNewCardNumber) && + isBuyExpiryValid && + buyNewCardCVC.length >= 3) + ); + async function fetchGiftCardBalance() { loadingBalance = true; try { @@ -1888,7 +1908,7 @@