Skip to content

Commit

Permalink
On delete account screen, add account number validation during input
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed Aug 30, 2023
1 parent 06745dd commit 9cc7a43
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,18 @@ class AccountDeletionContentView: UIView {
}
}

private var isAccountNumberLengthSatisfied: Bool {
let length = accountTextField.text?.count ?? 0
return length == 4
private var isInputValid: Bool {
guard let input = accountTextField.text,
let accountNumber = viewModel?.accountNumber,
!accountNumber.isEmpty
else {
return false
}

let inputLengthIsValid = input.count == 4
let inputMatchesAccountNumber = accountNumber.suffix(4) == input

return inputLengthIsValid && inputMatchesAccountNumber
}

weak var delegate: AccountDeletionContentViewDelegate?
Expand Down Expand Up @@ -326,7 +335,7 @@ class AccountDeletionContentView: UIView {
} else {
activityIndicator.stopAnimating()
}
deleteButton.isEnabled = isDeleteButtonEnabled && isAccountNumberLengthSatisfied
deleteButton.isEnabled = isDeleteButtonEnabled && isInputValid
statusLabel.text = text
statusLabel.textColor = textColor
}
Expand Down

0 comments on commit 9cc7a43

Please sign in to comment.