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

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

}

相关文章

正则替换html代码中img标签的src值在开发富文本信息在移动端...
正则表达式
AWK是一种处理文本文件的语言,是一个强大的文件分析工具。它...
正则表达式是特殊的字符序列,利用事先定义好的特定字符以及...
Python界一名小学生,热心分享编程学习。
收集整理每周优质开发者内容,包括、、等方面。每周五定期发...