Skip to content

Instantly share code, notes, and snippets.

@appyaaron
Last active December 27, 2015 15:59
Show Gist options
  • Save appyaaron/7351690 to your computer and use it in GitHub Desktop.
Save appyaaron/7351690 to your computer and use it in GitHub Desktop.
Check a string for a whitespace by creating an NSArray from an NSString separated by a whitespace. If this count is greater than one, then there is at least 1 whitespace.
NSArray *checkPasswordForWhitespace = [password.text componentsSeparatedByString:@" "];
NSLog(@"%@", checkPasswordForWhitespace);
if ([checkPasswordForWhitespace count] > 1) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whitespace" message:@"Please remove the whitespace from your password." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment