This file contains hidden or 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 { | |
let strippedString = <change replacements string so it fits your requirement - strip, trim, etc> | |
// replace current content with stripped content | |
if let replaceStart = textField.position(from: textField.beginningOfDocument, offset: range.location), | |
let replaceEnd = textField.position(from: replaceStart, offset: range.length), | |
let textRange = textField.textRange(from: replaceStart, to: replaceEnd) { | |
textField.replace(textRange, withText: strippedString) |