Check NSString for special characters

NSCharacterSet * set = [[NSCharacterSet alphanumericCharacterSet] invertedSet];

if ([aString rangeOfCharacterFromSet:set].location != NSNotFound) {
  NSLog(@"This string contains illegal characters");
}

You could also use a regex (this syntax is from RegexKitLite: http://regexkit.sourceforge.net ):

if ([aString isMatchedByRegex:@"[^a-zA-Z0-9]"]) {
  NSLog(@"This string contains illegal characters");
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)