I want to check an NSString for special characters, i.e. anything except a-z, A-Z and 0-9.
I don\'t need to check how many special characters are present, or their p
If you want to remove special characters & numbers from any string (even textfield text), while you are editing, these lines below are quite handy:
#define ACCEPTABLE_CHARACTERS @"!~`@#$%^&*-+();:=_{}[],.<>?\\/|\"\'0123456789"
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSCharacterSet *cs = [NSCharacterSet characterSetWithCharactersInString:ACCEPTABLE_CHARACTERS];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return (![string isEqualToString:filtered]) ? NO : YES;
}