//手机号码正则验证
- (BOOL)checkTel:(NSString *)str
{
if ([str length] == 0) {
[self showAlertView:@"请输入手机号码"];
return NO;
}
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) {
[self showAlertView:@"手机号码输入有误"];
return NO;
}else {
[self showAlertView:@"修改成功"];
}
return YES;
}
- (void)showAlertView:(NSString *)string {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:string delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
手机号码正则验证(试用版)
最新推荐文章于 2024-12-25 10:18:56 发布