手机号的判断:
+ (BOOL)isMobileNumber:(NSString *)mobileNum
{
NSString *pattern = @"^1+[34578]+\\d{9}";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
BOOL isMatch = [pred evaluateWithObject:mobileNum];
return isMatch;
}
邮箱的判断:
+ (BOOL)isValidateEmail:(NSString *)email {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}
车牌号的判断
+(BOOL)isValidateCar:(NSString *)car{
NSString *carRegex = @"^[A-Za-z]{1}[A-Za-z_0-9]{5}$";
NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
NSLog(@"carTest is %@",carTest);
return [carTest evaluateWithObject:car];
}
网友评论