美文网首页
iOS开发判断输入的是否为手机号、邮箱、车牌号

iOS开发判断输入的是否为手机号、邮箱、车牌号

作者: 维斯特洛荣 | 来源:发表于2018-02-27 14:44 被阅读0次

    手机号的判断:

    + (BOOL)isMobileNumber:(NSString *)mobileNum

    {

        NSString *pattern = @"^1+[34578]+\\d{9}";

        NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];

        BOOL isMatch = [pred evaluateWithObject:mobileNum];

        return isMatch;

    }

    邮箱的判断:

    + (BOOL)isValidateEmail:(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)isValidateCar:(NSString *)car{

        NSString *carRegex = @"^[A-Za-z]{1}[A-Za-z_0-9]{5}$";

        NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];

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

        return [carTest evaluateWithObject:car];

    }

    相关文章

      网友评论

          本文标题:iOS开发判断输入的是否为手机号、邮箱、车牌号

          本文链接:https://www.haomeiwen.com/subject/jlfmxftx.html