How would I go about allowing inputting only alphanumeric characters in an iOS UITextField
?
The RegEx way in Swift:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if string.isEmpty {
return true
}
let alphaNumericRegEx = "[a-zA-Z0-9]"
let predicate = NSPredicate(format:"SELF MATCHES %@", alphaNumericRegEx)
return predicate.evaluate(with: string)
}