ios-正则表达式密码格式判断

  // 密码格式判断  用户名由6-16个字符组成,区分大小写,不能为全数字组合,不能包含空格和@符号
    BOOL passwordNoAtTrue = NO; // 没有@吗
    BOOL passwrodNoSpaceTrue = NO; // 没有空格吗
    BOOL passwordNumTrue = NO; // 只有数字吗
    BOOL passwordLeast = NO; // 密码太短吗
    BOOL passwordSameTrue = NO;// 密码是否一致
    BOOL securityCodeTrue = YES;
    
    if (text2.text == nil || text2.text.length < 6 || text2.text.length > 16) {
        passwordLeast = YES;
    } else {
        NSString *regex = @"[^@]{6,16}$";
        NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
        if ([pred evaluateWithObject:text2.text]) {
            passwordNoAtTrue = YES;
        }
        NSString *regex1 = @"[^ ]{6,16}$";
        NSPredicate *pred1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex1];
        if ([pred1 evaluateWithObject:text2.text]) {
            passwrodNoSpaceTrue = YES;
        }
        NSString *regex2 = @"[0-9]{6,16}$";
        NSPredicate *pred2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex2];
        if ([pred2 evaluateWithObject:text2.text]) {
            passwordNumTrue = YES;
        }
        
        if (passwordNoAtTrue) {
            if ([text3.text isEqualToString:text2.text]) {
                passwordSameTrue = YES;
            }
        }
    }
    
    if (text4.text == nil || text4.text.length == 0) {
        securityCodeTrue = NO;
    }

你可能感兴趣的:(ios-正则表达式密码格式判断)