//包含数字和字母的密码长度6-16位
-(BOOL) validatePassword:(NSString *)password
{
//密码正则表达式
NSString *passwordRegex = @"^(?=.*?[a-zA-Z])(?=.*?[0-9])[a-zA-Z0-9]{6,16}$";
NSPredicate *passwordTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passwordRegex];
return [passwordTest evaluateWithObject:password];
}
-(BOOL) validateEmail:(NSString *)email
{
//邮箱正则表达式
NSString *emailRegex = @"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",emailRegex];
return [emailTest evaluateWithObject:email];
}
//手机号匹配11,12,13,14,15,16,17,18,19开头
-(BOOL) validateMobile:(NSString *)mobile
{
//手机正则表达式
NSString *mobileRegex = @"^(1[123456789][0-9]{9})$";
NSPredicate *mobileTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileRegex];
return [mobileTest evaluateWithObject:mobile];
}
-(BOOL) validateTel:(NSString *)tel
{
//传真,固定电话正则表达式
NSString *phoneRegex = @"^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
return [phoneTest evaluateWithObject:tel];
}