美文网首页
复杂的密码设置(使用正则)

复杂的密码设置(使用正则)

作者: 碎梦_aimee | 来源:发表于2020-03-12 10:34 被阅读0次

1.必须包含英文字母的大写、小写、数字,可且仅支持符号!_@-#.*%?

正则表达

NSString *emailRegex = @"^(?![^a-z]+$)(?![^A-Z]+$)(?!\\D+$)[!_@\\-#.*%?\\w]{8,15}$";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    //        return ![emailTest evaluateWithObject:self];
    
    if ([emailTest evaluateWithObject:self]) {
       
        return YES;
        
    }

2.不可包含2位以上相同的、顺序、逆序的数字、小写英文字母或大写英文字母(错误举例:111、012、321、abc、CBA、aaa)
正则表达

NSString *emailRegex = @"^(?!.*([!-~])\\1{2,})(?!.*(?:012|210|123|321|234|432|345|543|456|654|567|765|678|876|789|987))(?!.*(?:ABC|CBA|BCD|DCB|CDE|EDC|DEF|FED|EFG|GFE|FGH|HGF|GHI|IHG|HIJ|JIH|IJK|KJI|JKL|LKJ|KLM|MLK|LMN|NML|MNO|ONM|NOP|PON|OPQ|QPO|PQR|RQP|QRS|SRQ|RST|TSR|STU|UTS|TUV|VUT|UVW|WVU|VWX|XWV|WXY|YXW|XYZ|ZYX|abc|cba|bcd|dcb|cde|edc|def|fed|efg|gfe|fgh|hgf|ghi|ihg|hij|jih|ijk|kji|jkl|lkj|klm|mlk|lmn|nml|mno|onm|nop|pon|opq|qpo|pqr|rqp|qrs|srq|rst|tsr|stu|uts|tuv|vut|uvw|wvu|vwx|xwv|wxy|yxw|xyz|zyx)).+$";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    //        return ![emailTest evaluateWithObject:self];
    
    if ([emailTest evaluateWithObject:self]) {
       
        return YES;
        
    }
    
    return NO;

相关文章

网友评论

      本文标题:复杂的密码设置(使用正则)

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