正则表达式,登录注册验证,邮箱,手机,省份证号验证

//邮箱
+ (BOOL) validateEmail:(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];
}
  
  
//手机号码验证
+ (BOOL) validateMobile:(Nsstring *)mobile
{
    //手机号以13, 15,18开头,八个 \d 数字字符
    Nsstring *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    nspredicate *phoneTest = [nspredicate predicateWithFormat:@"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 = [nspredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
    NSLog(@"carTest is %@",carTest);
    return [carTest evaluateWithObject:carNo];
}
  
  
//车型
+ (BOOL) validateCarType:(Nsstring *)CarType
{
    Nsstring *CarTypeRegex = @"^[\u4E00-\u9FFF]+$";
    nspredicate *carTest = [nspredicate predicateWithFormat:@"SELF MATCHES %@",CarTypeRegex];
    return [carTest evaluateWithObject:CarType];
}
  
  
//用户名
+ (BOOL) validateUserName:(Nsstring *)name
{
    Nsstring *userNameRegex = @"^[A-Za-z0-9]{6,20}+$";
    nspredicate *userNamePredicate = [nspredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
    BOOL B = [userNamePredicate evaluateWithObject:name];
    return B;
}
  
  
//密码
+ (BOOL) validatePassword:(Nsstring *)passWord
{
    Nsstring *passWordRegex = @"^[a-zA-Z0-9]{6,20}+$";
    nspredicate *passWordPredicate = [nspredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:passWord];
}
  
  
//昵称
+ (BOOL) validateNickname:(Nsstring *)nickname
{
    Nsstring *nicknameRegex = @"^[\u4e00-\u9fa5]{4,8}$";
    nspredicate *passWordPredicate = [nspredicate predicateWithFormat:@"SELF MATCHES %@",nicknameRegex];
    return [passWordPredicate evaluateWithObject: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 = [nspredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:identityCard];
}

相关文章

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