iOS开发中邮箱,电话号码,身份证,密码,昵称正则表达式验证

热门标签

,

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!

//邮箱+ (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[emailTest evaluateWithObject:email];

}
//手机号码验证+ (BOOL) validateMobile:(NSString*)mobile{
//手机号以13, 15,18开头,八个 d 数字字符
NSString*phoneRegex =@"^((13[0-9])|(15[^4,\D])|(18[0,0-9]))\d{8}$";NSPredicate*phoneTest = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",phoneRegex];return[phoneTest evaluateWithObject: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[carTest evaluateWithObject:carNo];

}
//车型+ (BOOL) validateCarType:(NSString*)CarType

{NSString*CarTypeRegex =@"^[u4E00-u9FFF]+$";NSPredicate*carTest = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",CarTypeRegex];return[carTest evaluateWithObject:CarType];

}
//用户名+ (BOOL) validateUserName:(NSString*)name

{NSString*userNameRegex =@"^[A-Za-z0-9]{6,20}+$";NSPredicate*userNamePredicate = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",userNameRegex];BOOLB = [userNamePredicate evaluateWithObject:name];returnB;

}
//密码+ (BOOL) validatePassword:(NSString*)passWord

{NSString*passWordRegex =@"^[a-zA-Z0-9]{6,20}+$";NSPredicate*passWordPredicate = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",passWordRegex];return[passWordPredicate evaluateWithObject:passWord];
}
//昵称+ (BOOL) validateNickname:(NSString*)nickname

{NSString*nicknameRegex =@"^[u4e00-u9fa5]{4,8}$";NSPredicate*passWordPredicate = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",nicknameRegex];return[passWordPredicate evaluateWithObject:nickname];

}
//身份证号+ (BOOL) validateIdentityCard: (NSString*)identityCard

{BOOLflag;if(identityCard.length <=0) {

flag =NO;returnflag;

}NSString*regex2 =@"^(\d{14}|\d{17})(\d|[xX])$";NSPredicate*identityCardPredicate = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",regex2];return[identityCardPredicate evaluateWithObject:identityCard];

 

未经允许不得转载:作者:SheaYang, 转载或复制请以 超链接形式 并注明出处 技术狗|博客
原文地址:《iOS开发中邮箱,电话号码,身份证,密码,昵称正则表达式验证》 发布于2019-09-20

分享到:
赞(0)

评论 1

5 + 7 =
  1. #1

    666 好的很

    管理员SheaYang3个月前 (09-20)回复
iOS开发中邮箱,电话号码,身份证,密码,昵称正则表达式验证

长按图片转发给朋友

Vieu4.0主题
专业打造轻量级个人企业风格博客主题!专注于前端开发,全站响应式布局自适应模板。

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

Q Q 登 录
微 博 登 录