UITextField — Restrict textfield to a certain character (iOS)

If you want to perform a user input validation of your textfield use the following code snippet:

// MARK: - UITextFieldDelegatelet allowedCharacters = CharacterSet(charactersIn:”0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz”).invertedfunc textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {let components = string.components(separatedBy: allowedCharacters)
let filtered = components.joined(separator: "")if string == filtered {
return…