[ 登录注册 ]

ios

iphone开发用正则判断邮箱、密码是否正确

2016/08/11 11:19 [db:作者] 返回上一页

 

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

 

}

点击复制链接 与好友分享!回本站首页

文章来源:http://www.bozhiyue.com/ios/2016/0811/364085.html
评论
发表评论