fix(payment): accept either 2-digit or 4-digit years in card expiry validation
This commit is contained in:
@@ -1116,9 +1116,9 @@ struct PaymentCardView: View {
|
||||
_cpf = State(initialValue: appState.wrappedValue.profile.cpf)
|
||||
}
|
||||
|
||||
private func validateExpiryDate(digits: Int) -> Bool {
|
||||
private func validateExpiryDate() -> Bool {
|
||||
let clean = expiry.filter(\.isNumber)
|
||||
guard clean.count == digits else { return false }
|
||||
guard clean.count == 4 || clean.count == 6 else { return false }
|
||||
let monthStr = String(clean.prefix(2))
|
||||
guard let month = Int(monthStr), (1...12).contains(month) else { return false }
|
||||
return true
|
||||
@@ -1127,7 +1127,7 @@ struct PaymentCardView: View {
|
||||
var canSubmit: Bool {
|
||||
holderName.trimmingCharacters(in: .whitespaces).isEmpty == false &&
|
||||
cardNumber.filter(\.isNumber).count >= 13 &&
|
||||
validateExpiryDate(digits: 4) &&
|
||||
validateExpiryDate() &&
|
||||
cvv.filter(\.isNumber).count >= 3 &&
|
||||
cpf.filter(\.isNumber).count == 11
|
||||
}
|
||||
@@ -1673,9 +1673,9 @@ struct ChangePaymentNewCardView: View {
|
||||
_cpf = State(initialValue: appState.wrappedValue.profile.cpf)
|
||||
}
|
||||
|
||||
private func validateExpiryDate(digits: Int) -> Bool {
|
||||
private func validateExpiryDate() -> Bool {
|
||||
let clean = expiry.filter(\.isNumber)
|
||||
guard clean.count == digits else { return false }
|
||||
guard clean.count == 4 || clean.count == 6 else { return false }
|
||||
let monthStr = String(clean.prefix(2))
|
||||
guard let month = Int(monthStr), (1...12).contains(month) else { return false }
|
||||
return true
|
||||
@@ -1684,7 +1684,7 @@ struct ChangePaymentNewCardView: View {
|
||||
var canSubmit: Bool {
|
||||
holderName.trimmingCharacters(in: .whitespaces).isEmpty == false &&
|
||||
cardNumber.filter(\.isNumber).count >= 13 &&
|
||||
validateExpiryDate(digits: 6) &&
|
||||
validateExpiryDate() &&
|
||||
cvv.filter(\.isNumber).count >= 3 &&
|
||||
cpf.filter(\.isNumber).count == 11
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user