Reputation: 307
i want to validate string for following condition
does any one have any idea which is the the best way to do this?
Thanks in advance
Upvotes: 0
Views: 289
Reputation: 523484
NSCharacterSet* uppercaseCharSet = [NSCharacterSet uppercaseLetterCharacterSet];
if ([theString rangeOfCharacterFromSet:uppercaseCharSet].location == NSNotFound)
return NO;
NSCharacterSet* lowercaseCharSet = [NSCharacterSet lowercaseLetterCharacterSet];
if ([theString rangeOfCharacterFromSet:lowercaseCharSet].location == NSNotFound)
return NO;
NSCharacterSet* digitsCharSet = [NSCharacterSet decimalDigitCharacterSet];
if ([theString rangeOfCharacterFromSet:digitsCharSet].location == NSNotFound)
return NO;
return YES;
This method is Unicode-aware. If by "Upper case charecter" you just mean A-Z, use
NSCharacterSet* uppercaseCharSet =
[NSCharacterSet characterSetWithRange:NSMakeRange('A', 26)];
and similar for the other two.
Upvotes: 2