int letter = 0;
int digit = 0;
int other = 0;
for(NSUInteger i = 0; i < [text length]; i++) {
int a = [text characterAtIndex:i];
BOOL letterFlag = [[NSCharacterSet letterCharacterSet] characterIsMember:a];
BOOL digitFlag = [[NSCharacterSet decimalDigitCharacterSet] characterIsMember:a];
if (letterFlag) {
letter = 1;
}
else if (digitFlag)
{
digit = 1;
}
else
{
other=1;
}
}
return letter == 1 && (other + digit > 0) && text.length >= 6 && text.length <= 20;
判断密码有效性,主要用到了
NSCharacterSet中的一些api