Here is what I will do. Create regular expressions for each condition that you need to check if the corresponding value is present.
i.e. A regular expression to check if it has one uppercase letter, one lowercase letter, one integer and one special character, etc.
and then use the same line to check for each regular expression, if all of them return true, you have a winner, if not, then the line does not meet your criteria.
// Example for Validating UpperCaseLetter does the same for everyone else with the appropriate regular expression.
-(BOOL) validateOneUpperCaseLetter:(NSString *)string { if ((string == nil) || ([string isEqualToString: @""])) { return NO; } // Change this regEx to one you needed. // this one validates for the "name". NSString *regEx = @"^[a-zA-Z]+(([\\'\\,\\.\\ -][a-zA-Z])?[a-zA-Z]\\s*)*$"; NSPredicate *regExPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regEx]; BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject: string]; if (!myStringMatchesRegEx) { return NO; } return YES;}
kthorat
source share