How would I, in objective-c, make it so only strings with a-z characters were allowed? I.E. no & characters, no – characters, etc.
Thanks!
Christian Stewart
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.
NSCharacterSets are going to be the key here. First you’ll need the character set of alphabetical characters:And then, if you want to check if the string contains a character that’s not a letter, you can use this set’s inverse:
Then use
NSString‘srangeOfCharacterFromSet:withnotLetters, and if the range doesn’t start withNSNotFound, there are forbidden characters in your string.