#import "NSString+Extension.h"
#define NULLString(string) ((![string isKindOfClass:[NSString class]])||[string isEqualToString:@""] || (string == nil) || [string isEqualToString:@""] || [string isKindOfClass:[NSNull class]]||[[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0)
@implementation NSString (Extension)
- (NSString *)validationPassword:(NSString *)password{
// 判断密码不能包含空格 和要符合规则
NSRange range = [password rangeOfString:@" "];
NSString *validate = @"^(?=.*\\d)((?=.*[a-z])(?=.*[A-Z])(?=.*\\W).\\S{7,63})$";
NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",validate];
// 判断密码是否为空
if (NULLString(password)) {
return @"密码不能为空不符合规则";
} else {
if (range.location != NSNotFound) {
return @"密码包含空格不符合规则";
} else {
if ([numberPre evaluateWithObject:password]) {
return @"修改成功";
} else {
return @"密码不符合规则";
}
}
}
return nil;
}
@end
密码8到64位大小写字母+数字+字符 不能包含空格
最新推荐文章于 2024-07-13 13:17:12 发布