(IOS)判斷密碼格式

weixin_33895657發表於2018-12-26

+(BOOL)validateWithPassword:(NSString *)password

{

    //密碼只包含字母,數字,字元中至少兩種

    NSString * regex =@"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{6,18}$";

    NSPredicate * pas= [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];

    return[pas evaluateWithObject:password];

}

相關文章