微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

注册页面的各种判断正则表达式

1.密码判断

至少包含数字、字母(区分大小写)、符号中的2

Nsstring *regex = @"^(?![A-Z]+$)(?![a-z]+$)(?!\\d+$)(?![\\W_]+$)\\S+$";
            nspredicate *predicate = [nspredicate predicateWithFormat:@"self matches %@",regex];

 if ([predicate evaluateWithObject:textField.text] == NO) {
              
        UIAlertView *alerview =[ [UIAlertView alloc]initWithTitle:nil message:@"至少包含数字、字母(区分大小写)、符号中的2种。" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil,nil];
         
        [alerview show];
        [alerview release];
              
            }
2 .手机号码的确认

  Nsstring *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
  nspredicate *predicate = [nspredicate predicateWithFormat:@"SELF MATCHES %@",regex];
  if (![textField.text isEqualToString:@""]&&[predicate evaluateWithObject:textField.text] == NO) {
          UIAlertView *alerview =[ [UIAlertView alloc]initWithTitle:nil message:@"请输入正确的手机号码" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil,nil];
          [alerview show];
          [alerview release];
            }
3.限制用户名特征应该是3 - 10 之间 :

^.{3,10}$


4.电子邮件

[A-Z0-9a-z._%+-]{3,}+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}


5. 密码必须包含字母数字字符

[A-Za-z0-9]{6,20}


6.电话号码必须在适当的格式(如。# # # - # # # - # # # #)

[0-9]{3}\\-[0-9]{3}\\-[0-9]{4}

原文地址:https://www.jb51.cc/regex/361329.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐