fix(payment): validate card expiry date month range and fix PaymentCardView character length

This commit is contained in:
Daniel Arantes Loverde
2026-06-04 15:48:00 -03:00
parent 2809131c25
commit f49e4ea337
2 changed files with 50 additions and 13 deletions

View File

@@ -1116,10 +1116,18 @@ struct PaymentCardView: View {
_cpf = State(initialValue: appState.wrappedValue.profile.cpf)
}
private func validateExpiryDate(digits: Int) -> Bool {
let clean = expiry.filter(\.isNumber)
guard clean.count == digits else { return false }
let monthStr = String(clean.prefix(2))
guard let month = Int(monthStr), (1...12).contains(month) else { return false }
return true
}
var canSubmit: Bool {
holderName.trimmingCharacters(in: .whitespaces).isEmpty == false &&
cardNumber.filter(\.isNumber).count >= 13 &&
expiry.filter(\.isNumber).count == 6 &&
validateExpiryDate(digits: 4) &&
cvv.filter(\.isNumber).count >= 3 &&
cpf.filter(\.isNumber).count == 11
}
@@ -1665,10 +1673,18 @@ struct ChangePaymentNewCardView: View {
_cpf = State(initialValue: appState.wrappedValue.profile.cpf)
}
private func validateExpiryDate(digits: Int) -> Bool {
let clean = expiry.filter(\.isNumber)
guard clean.count == digits else { return false }
let monthStr = String(clean.prefix(2))
guard let month = Int(monthStr), (1...12).contains(month) else { return false }
return true
}
var canSubmit: Bool {
holderName.trimmingCharacters(in: .whitespaces).isEmpty == false &&
cardNumber.filter(\.isNumber).count >= 13 &&
expiry.filter(\.isNumber).count == 6 &&
validateExpiryDate(digits: 6) &&
cvv.filter(\.isNumber).count >= 3 &&
cpf.filter(\.isNumber).count == 11
}