I want the keyboard for the UITextfield to only have a-z, no numbers, no special characters (!@$!@$@!#), and no caps. Basicly I am going for a keyboard with only the alphabet.>
class ViewController: UIViewController,UITextFieldDelegate {
@IBOutlet var phoneTextField:UITextField!
override func viewDidLoad() {
super.viewDidLoad()
self.phoneTextField.delegate = self
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
{
let textString = (textField.text! as NSString).replacingCharacters(in: range, with: string)
if textField == self.phoneTextField && string.characters.count > 0 {
let LettersOnly = NSCharacterSet.Letters
let strValid = LettersOnly.contains(UnicodeScalar.init(string)!)
return strValid && textString.characters.count <= 10
}
return true
}
}
Try this code
In above code is only allow 10 char in text field