阳光网驿-企业信息化交流平台【DTC零售连锁全渠道解决方案】

 找回密码
 注册

QQ登录

只需一步,快速开始

扫描二维码登录本站

手机号码,快捷登录

老司机
查看: 1187|回复: 0

[转帖] 正则表达式在Android平台的应用

[复制链接]
  • TA的每日心情
    开心
    2012-3-7 10:15
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    发表于 2012-1-5 11:12:45 | 显示全部楼层 |阅读模式
    [代码] [Java]代码public int doCheck(String name, String pass, String repass, String email) {
      String regex = "([a-z]|[A-Z]|[0-9]|[\\u4e00-\\u9fa5])+";
      Pattern pat = Pattern.compile(regex);
      int name_length = name.length();
      int pass_length = pass.length();
      int temp = 0;
      if ((!(name_length >= 3 && name_length <= 20))
        || !pat.matcher(name).matches()) {
       temp = 1;
      }
      if ((!(pass_length >= 4 && pass_length <= 20))
        || !pat.matcher(pass).matches()) {
       temp = 2;
      }
      if (!pass.equals(repass)) {
       temp = 3;
      }
      if (!Pattern.compile("[url=file://\\w+@(\\w+.)+[a-z]{2,3}]\\w+@(\\w+.)+[a-z]{2,3}").matcher(email[/url])
      .matches()) {
       temp = 4;
      }
      return temp;
    }
    楼主热帖
    启用邀请码注册,提高发帖质量,建设交流社区
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    快速回复 返回顶部 返回列表