正则法则

//邮箱

- (BOOL) validateEmail:(Nsstring *)email

{

Nsstring *emailRegex =@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";

nspredicate *emailTest = [nspredicatepredicateWithFormat:@"SELF MATCHES %@",emailRegex];

return [emailTestevaluateWithObject:email];

}


//手机号码验证

- (BOOL) validateMobile:(Nsstring *)mobile

{

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

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

nspredicate *phoneTest = [nspredicatepredicateWithFormat:@"SELF MATCHES %@",phoneRegex];

return [phoneTestevaluateWithObject:mobile];

}



//车牌号验证

- (BOOL) validateCarNo:(Nsstring *)carNo

{

Nsstring *carRegex =@"^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$";

nspredicate *carTest = [nspredicatepredicateWithFormat:@"SELF MATCHES %@",carRegex];

NSLog(@"carTest is %@",carTest);

return [carTestevaluateWithObject:carNo];

}



//车型

- (BOOL) validateCarType:(Nsstring *)CarType

{

Nsstring *CarTypeRegex =@"^[\u4E00-\u9FFF]+$";

nspredicate *carTest = [nspredicatepredicateWithFormat:@"SELF MATCHES %@",CarTypeRegex];

return [carTestevaluateWithObject:CarType];

}


//用户名

- (BOOL) validateUserName:(Nsstring *)name

{

Nsstring *userNameRegex =@"^[A-Za-z0-9]{6,20}+$";

nspredicate *userNamePredicate = [nspredicatepredicateWithFormat:@"SELF MATCHES %@",userNameRegex];

BOOL B = [userNamePredicateevaluateWithObject:name];

return B;

}



//密码

- (BOOL) validatePassword:(Nsstring *)passWord

{

Nsstring *passWordRegex =@"^[a-zA-Z0-9]{6,20}+$";

nspredicate *passWordPredicate = [nspredicatepredicateWithFormat:@"SELF MATCHES %@",passWordRegex];

return [passWordPredicateevaluateWithObject:passWord];

}



//昵称

- (BOOL) validateNickname:(Nsstring *)nickname

{

Nsstring *nicknameRegex =@"^[\u4e00-\u9fa5]{4,8}$";

nspredicate *passWordPredicate = [nspredicatepredicateWithFormat:@"SELF MATCHES %@",nicknameRegex];

return [passWordPredicateevaluateWithObject:nickname];

}



//身份证号

- (BOOL) validateIdentityCard: (Nsstring *)identityCard

{

BOOL flag;

if (identityCard.length <= 0) {

flag = NO;

return flag;

}

Nsstring *regex2 =@"^(\\d{14}|\\d{17})(\\d|[xX])$";

nspredicate *identityCardPredicate = [nspredicatepredicateWithFormat:@"SELF MATCHES %@",regex2];

return [identityCardPredicateevaluateWithObject:identityCard];

}

相关文章

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