diff --git a/AnimatedField/Classes/AnimatedField+TextFieldDelegate.swift b/AnimatedField/Classes/AnimatedField+TextFieldDelegate.swift index 94c37ae..3281aba 100644 --- a/AnimatedField/Classes/AnimatedField+TextFieldDelegate.swift +++ b/AnimatedField/Classes/AnimatedField+TextFieldDelegate.swift @@ -19,17 +19,16 @@ extension AnimatedField: UITextFieldDelegate { // Copy new character var newInput = string - - // Replace special characters in newInput - newInput = newInput.replacingOccurrences(of: "`", with: "") - newInput = newInput.replacingOccurrences(of: "^", with: "") - newInput = newInput.replacingOccurrences(of: "¨", with: "") - - // Replace special characters in textField - textField.text = textField.text?.replacingOccurrences(of: "`", with: "") - textField.text = textField.text?.replacingOccurrences(of: "^", with: "") - textField.text = textField.text?.replacingOccurrences(of: "¨", with: "") - + + let invalidCharacters = format.invalidCharacters.map { String($0) } + for invalidCharacter in invalidCharacters { + // Replace special characters in newInput + newInput = newInput.replacingOccurrences(of: invalidCharacter, with: "") + + // Replace special characters in textField + textField.text = textField.text?.replacingOccurrences(of: invalidCharacter, with: "") + } + // Apply uppercased & lowercased if available if uppercased { newInput = newInput.uppercased() } if lowercased { newInput = newInput.lowercased() } diff --git a/AnimatedField/Classes/AnimatedField+TextViewDelegate.swift b/AnimatedField/Classes/AnimatedField+TextViewDelegate.swift index 7214e89..c08a977 100644 --- a/AnimatedField/Classes/AnimatedField+TextViewDelegate.swift +++ b/AnimatedField/Classes/AnimatedField+TextViewDelegate.swift @@ -18,17 +18,16 @@ extension AnimatedField: UITextViewDelegate { // Copy new character var newInput = text - - // Replace special characters in newInput - newInput = newInput.replacingOccurrences(of: "`", with: "") - newInput = newInput.replacingOccurrences(of: "^", with: "") - newInput = newInput.replacingOccurrences(of: "¨", with: "") - - // Replace special characters in textView - textView.text = textView.text?.replacingOccurrences(of: "`", with: "") - textView.text = textView.text?.replacingOccurrences(of: "^", with: "") - textView.text = textView.text?.replacingOccurrences(of: "¨", with: "") - + + let invalidCharacters = format.invalidCharacters.map { String($0) } + for invalidCharacter in invalidCharacters { + // Replace special characters in newInput + newInput = newInput.replacingOccurrences(of: invalidCharacter, with: "") + + // Replace special characters in textView + textView.text = textView.text?.replacingOccurrences(of: invalidCharacter, with: "") + } + // Apply uppercased & lowercased if available if uppercased { newInput = newInput.uppercased() } if lowercased { newInput = newInput.lowercased() } diff --git a/AnimatedField/Classes/AnimatedFieldFormat.swift b/AnimatedField/Classes/AnimatedFieldFormat.swift index b039713..7bf32bc 100644 --- a/AnimatedField/Classes/AnimatedFieldFormat.swift +++ b/AnimatedField/Classes/AnimatedFieldFormat.swift @@ -9,10 +9,13 @@ import Foundation public struct AnimatedFieldFormat { - + + /// String of characters to block/filter from input + public var invalidCharacters = "`^¨" + /// Title always visible public var titleAlwaysVisible = false - + /// Font for title label public var titleFont = UIFont.systemFont(ofSize: 13, weight: .regular)