首页 > 移动平台 > 详细

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

时间:2014-07-21 10:26:59      阅读:454      评论:0      收藏:0      [点我收藏+]

#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://my.oschina.net/751547752/blog/290676

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!