是否是正确的邮箱格式
+ (BOOL)isValidateEmail:(NSString *)email
{
NSString *regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
return [predicate evaluateWithObject:email];
}
是否是正确的手机号码格式
+ (BOOL)isValidateMobile:(NSString *)mobile
{
NSString *regex = @"^((13[0-9])|(14[5,7])|(15[^4,\\D])|(18[0,0-9])|(17[0,5-8]))\\d{8}$";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
return [predicate evaluateWithObject:mobile];
}
正则匹配用户密码6-18位数字和字母组合
+ (BOOL)checkPassword:(NSString *) password
{
// 正则匹配用户密码6-18位数字和字母组合
NSString *pattern = @"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{6,18}";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
BOOL isMatch = [pred evaluateWithObject:password];
return isMatch;
}
网友评论