正则表达式

1、判断用户名,在2-16位

-(BOOL)CheckInput:(NSString *)_text

 

{

    NSString *Regex = @"^\\w{2,16}$";

    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];

    return [emailTest evaluateWithObject:_text];

}

 

 

2、判断手机号码,1开头的十一位数字

-(BOOL)CheckInput:(NSString *)_text

{

    NSString *Regex = @"1\\d{10}";

    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];

    return [emailTest evaluateWithObject:_text];

}

 

 

3、判断邮箱

-(BOOL)CheckInput:(NSString *)_text

{

    NSString *Regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";

    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];

    return [emailTest evaluateWithObject:_text];

}

 

 

 

4、判断密码,6-16位 

-(BOOL)CheckInput:(NSString *)_text

{

    NSString *Regex = @"\\w{6,16}";

    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];

    return [emailTest evaluateWithObject:_text];

}

 

posted @ 2014-08-21 21:28  蜗牛强  阅读(138)  评论(0编辑  收藏  举报