//邮箱
- (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, 15,18开头,八个 \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];
}