//邮箱
+ (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];
}
正则表达式常用判断
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 判断手机所属运营商 判断手机号是否正确 判断用户身份证号码15位或者18位 判断用户姓名,20位的中文或英文 检测...
- 正则 1 . 修饰词i :匹配时忽略大小写 g : 匹配时全局匹配,查找所有匹配项,而非查找到一个既停止2 . 匹...