码迷,mamicode.com
首页 > 移动开发 > 详细

NSPredicate判断手机号、邮箱、qq、重名、

时间:2014-07-21 10:27:02      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:http   os   io   for   re   c   

#import <Foundation/Foundation.h>


@interface NSString (InputCheck)

- (BOOL) validateEmail;

- (BOOL) validateMobile;

- (BOOL) validateqq;

- (BOOL) validateRealName;

- (BOOL) validateNickName;

- (BOOL) validateUserId;

@end

//---------------------------------------------------

#import "NSString+InputCheck.h"


@implementation NSString (InputCheck)

- (BOOL) validateEmail

{

    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:self];

}


// ^[0-9]+$


- (BOOL) validateMobile

{

    //手机号以13 1518开头,八个 \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:self];

}


- (BOOL) validateUserId

{

    NSString *userIdRegex = @"^[0-9]+$";

    NSPredicate *userIdPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userIdRegex];

    BOOL B = [userIdPredicate evaluateWithObject:self];

    if (![self hasPrefix:@"1"] && B) {

        return NO;

    }

    return B;

}


- (BOOL) validateqq

{

    NSString *qqRegex = @"^[0-9]+$";

    NSPredicate *qqTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",qqRegex];

    return [qqTest evaluateWithObject:self];

}


- (BOOL) validateRealName

{

    NSString *nicknameRegex = @"^[\u4e00-\u9fa5]{2,8}$";

    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",nicknameRegex];

    return [passWordPredicate evaluateWithObject:self];

}


- (BOOL) validateNickName

{

    NSString *userNameRegex = @"^[A-Za-z0-9\u4e00-\u9fa5]{1,24}+$";

    NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];

    BOOL B = [userNamePredicate evaluateWithObject:self];

    return B;

}

@end


NSPredicate判断手机号、邮箱、qq、重名、,布布扣,bubuko.com

NSPredicate判断手机号、邮箱、qq、重名、

标签:http   os   io   for   re   c   

原文地址:http://my.oschina.net/751547752/blog/290676

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!