判斷密碼是否包含字母,數字以及其他字符
+(BOOL)isStringContainNumberWith:(NSString *)str{
//數字條件
NSRegularExpression *tNumRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[0-9]" options:NSRegularExpressionCaseInsensitive error:nil];
//符合數字條件的有幾個字節(jié)
NSUInteger tNumMatchCount = [tNumRegularExpression numberOfMatchesInString:str options:NSMatchingReportProgress range:NSMakeRange(0, str.length)];
//英文字條件
NSRegularExpression *tLetterRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[A-Za-z]" options:NSRegularExpressionCaseInsensitive error:nil];
//符合英文字條件的有幾個字節(jié)
NSUInteger tLetterMatchCount = [tLetterRegularExpression numberOfMatchesInString:str options:NSMatchingReportProgress range:NSMakeRange(0, str.length)];
if (tNumMatchCount == str.length) {
NSLog(@"全部數字膳凝,沒有英文");
return NO;
} else if (tLetterMatchCount == str.length) {
NSLog(@"全部英文宾抓,沒有數字");
return NO;
} else if (tNumMatchCount + tLetterMatchCount == str.length) {
NSLog(@"英文和符合數字條件的相加等于密碼長度谈火,達到密碼強度最低要求");
return YES;
} else {
NSLog(@"可能包含標點符號的情況,或是包含非英文的文字");
return YES;
}
}