栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android开发中超好用的正则表达式工具类RegexUtil完整实例

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android开发中超好用的正则表达式工具类RegexUtil完整实例

本文实例讲述了Android开发中超好用的正则表达式工具类RegexUtil。分享给大家供大家参考,具体如下:


public class RegexUtil {
  
  public static final Pattern PLATE_NUMBER_PATTERN = Pattern
      .compile("^[u0391-uFFE5]{1}[a-zA-Z0-9]{6}$");
  
  public static final Pattern ID_CODE_PATTERN = Pattern
      .compile("^[a-zA-Z0-9]+$");
  
  public static final Pattern CODE_PATTERN = Pattern
      .compile("^[a-zA-Z0-9]+$");
  
  public static final Pattern PHONE_NUMBER_PATTERN = Pattern
      .compile("0\d{2,3}-[0-9]+");
  
  public static final Pattern POST_CODE_PATTERN = Pattern.compile("\d{6}");
  
  public static final Pattern AREA_PATTERN = Pattern.compile("\d*.?\d*");
  
  public static final Pattern MOBILE_NUMBER_PATTERN = Pattern
      .compile("\d{11}");
  
  public static final Pattern ACCOUNT_NUMBER_PATTERN = Pattern
      .compile("\d{16,21}");
  
  public static boolean isPlateNumber(String s) {
    Matcher m = PLATE_NUMBER_PATTERN.matcher(s);
    return m.matches();
  }
  
  public static boolean isIDCode(String s) {
    Matcher m = ID_CODE_PATTERN.matcher(s);
    return m.matches();
  }
  
  public static boolean isCode(String s) {
    Matcher m = CODE_PATTERN.matcher(s);
    return m.matches();
  }
  
  public static boolean isPhoneNumber(String s) {
    Matcher m = PHONE_NUMBER_PATTERN.matcher(s);
    return m.matches();
  }
  
  public static boolean isPostCode(String s) {
    Matcher m = POST_CODE_PATTERN.matcher(s);
    return m.matches();
  }
  
  public static boolean isArea(String s) {
    Matcher m = AREA_PATTERN.matcher(s);
    return m.matches();
  }
  
  public static boolean isMobileNumber(String s) {
    Matcher m = MOBILE_NUMBER_PATTERN.matcher(s);
    return m.matches();
  }
  
  public static boolean isAccountNumber(String s) {
    Matcher m = ACCOUNT_NUMBER_PATTERN.matcher(s);
    return m.matches();
  }
}

PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:

Javascript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript

正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android控件用法总结》、《Android开发入门与进阶教程》、《Android视图View技巧总结》、《Android编程之activity操作技巧总结》、《Android数据库操作技巧总结》及《Android资源操作技巧汇总》

希望本文所述对大家Android程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/157294.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号