Checking NSString for Special Characters | iOS Programmer Guide

To check an NSString for special characters, we can use 'NSCharacterSet'.
First we need to instantiate an NSCharacterSet as below with the property 'characterSetWithCharactersInString'
NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ0123456789"] invertedSet];
Then check the actual NSString for any of the characters in the NSCharacterSet instantiated already.
if ([aString rangeOfCharacterFromSet:set].location != NSNotFound) {
  NSLog(@"This string contains illegal characters");
}
Here, if the NSString contains other than a-z,A-Z and 0-9 NSLog will log that this string contains illegal characters.