Skip to content

Instantly share code, notes, and snippets.

@DisappearPing
Last active May 5, 2022 03:27
Show Gist options
  • Save DisappearPing/935c2487dde69e6500959894167b4265 to your computer and use it in GitHub Desktop.
Save DisappearPing/935c2487dde69e6500959894167b4265 to your computer and use it in GitHub Desktop.
dynamic block enter text in textfield delegate
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard textField == self.exportAmountTextField else { return true }
let oldString: NSString = (textField.text ?? "") as NSString
let resultString = oldString.replacingCharacters(in: range, with: string)
let doubleString = Double(resultString) ?? 0
if (string.trimmingCharacters(in: CharacterSet.decimalDigits).count == 0 || string == "" || string == ".") == false {
return false
}
if resultString.components(separatedBy: ".").last?.count ?? 7 > 6 {
return false
}
if (doubleString > twipAmount) || (doubleString > Double(99999999)) {
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment