Last active
May 5, 2022 03:27
-
-
Save DisappearPing/935c2487dde69e6500959894167b4265 to your computer and use it in GitHub Desktop.
dynamic block enter text in textfield delegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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