美文网首页
iOS 密码强度判断

iOS 密码强度判断

作者: 旅途开发者 | 来源:发表于2019-07-10 15:28 被阅读0次

    判断密码是否包含字母,数字以及其他字符

    +(BOOL)isStringContainNumberWith:(NSString *)str{
        //数字条件
        NSRegularExpression *tNumRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[0-9]" options:NSRegularExpressionCaseInsensitive error:nil];
        //符合数字条件的有几个字节
        NSUInteger tNumMatchCount = [tNumRegularExpression numberOfMatchesInString:str options:NSMatchingReportProgress range:NSMakeRange(0, str.length)];
        //英文字条件
        NSRegularExpression *tLetterRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[A-Za-z]" options:NSRegularExpressionCaseInsensitive error:nil];
        //符合英文字条件的有几个字节
        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;
        }
    }

    相关文章

      网友评论

          本文标题:iOS 密码强度判断

          本文链接:https://www.haomeiwen.com/subject/bpyhkctx.html