- (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, 15,18开头,八个 \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];
}
原文地址:https://www.jb51.cc/regex/360715.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。