正则表达式。。。手机号判断 一个方法就搞定了
-(void)checkTel:(NSString *)str
{
NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isMatch = [pred evaluateWithObject:str];
if (!isMatch)
{
[MBProgressHUD showError:@"请输入正确的手机号"];
return;
}
[self.myTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:0]];
}
就是这样 喵。。。。
下面是限制textfiled的长度
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([string isEqualToString:@"\n"])
{
return YES;
}
NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (self.tf3 == textField)
{
if ([toBeString length] > 11)
{
textField.text = [toBeString substringToIndex:11];
[MBProgressHUD showError:@"字符数超过最大限制"];
return NO;
}
}
return YES;
}