How would I go about allowing inputting only alphanumeric characters in an iOS UITextField?
How would I go about allowing inputting only alphanumeric characters in an iOS UITextField
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the UITextFieldDelegate method
-textField:shouldChangeCharactersInRange:replacementString:with an NSCharacterSet containing the inverse of the characters you want to allow. For example:Note that you’ll need to declare that your class implements the protocol (i.e.
@interface MyClass : SomeSuperclass <UITextFieldDelegate>) and set the text field’sdelegateto the instance of your class.