加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则验证手机号,邮箱,车牌

发布时间:2020-12-14 01:24:56 所属栏目:百科 来源:网络整理
导读:- ( IBAction )button_Click:( id )sender { if ([ self isValidateMobile : @" 输入你要验证的手机号码 " ] == YES ) { NSLog ( @" 手机号正确 " ); } else { NSLog ( @" 手机号错误 " ); } if ([ self isValidateEmail : @" 输入你要验证的邮箱 " ] == YES

- (IBAction)button_Click:(id)sender {

if ([self isValidateMobile:@"输入你要验证的手机号码"] == YES) {

NSLog(@"手机号正确");

}else{

NSLog(@"手机号错误");

}

if ([self isValidateEmail:@"输入你要验证的邮箱"] == YES) {

NSLog(@"邮箱正确");

}else{

NSLog(@"邮箱错误");

}

}

/*手机号码验证 MODIFIED BY HELENSONG*/

-(BOOL) isValidateMobile:(NSString *)mobile

{

//手机号以13 1518开头,八个 d 数字字符

NSString *phoneRegex = @"^((13[0-9])|(15[^4,D])|(18[0,0-9]))d{8}$";

NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];

//NSLog(@"phoneTest is %@",phoneTest);

return [phoneTest evaluateWithObject:mobile];

}


/*车牌号验证 MODIFIED BY HELENSONG*/

BOOL validateCarNo(NSString* carNo)

{

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:carNo];

}


/*邮箱验证 MODIFIED BY HELENSONG*/

-(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];

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读