Android开发中正则表达式工具类RegexUtil的示例分析

发布时间:2021-08-25 14:48:44 作者:小新
来源:亿速云 阅读:147

小编给大家分享一下Android开发中正则表达式工具类RegexUtil的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

具体如下:

/***********************************************
 * 正则表达式工具
 *
 * @author chen.lin
 * @version 1.0
 ************************************************/
public class RegexUtil {
  /**
   * 车牌号码Pattern
   */
  public static final Pattern PLATE_NUMBER_PATTERN = Pattern
      .compile("^[\u0391-\uFFE5]{1}[a-zA-Z0-9]{6}$");
  /**
   * 证件号码Pattern
   */
  public static final Pattern ID_CODE_PATTERN = Pattern
      .compile("^[a-zA-Z0-9]+$");
  /**
   * 编码Pattern
   */
  public static final Pattern CODE_PATTERN = Pattern
      .compile("^[a-zA-Z0-9]+$");
  /**
   * 固定电话编码Pattern
   */
  public static final Pattern PHONE_NUMBER_PATTERN = Pattern
      .compile("0\\d{2,3}-[0-9]+");
  /**
   * 邮政编码Pattern
   */
  public static final Pattern POST_CODE_PATTERN = Pattern.compile("\\d{6}");
  /**
   * 面积Pattern
   */
  public static final Pattern AREA_PATTERN = Pattern.compile("\\d*.?\\d*");
  /**
   * 手机号码Pattern
   */
  public static final Pattern MOBILE_NUMBER_PATTERN = Pattern
      .compile("\\d{11}");
  /**
   * 银行帐号Pattern
   */
  public static final Pattern ACCOUNT_NUMBER_PATTERN = Pattern
      .compile("\\d{16,21}");
  /**
   * 车牌号码是否正确
   *
   * @param s
   * @return
   */
  public static boolean isPlateNumber(String s) {
    Matcher m = PLATE_NUMBER_PATTERN.matcher(s);
    return m.matches();
  }
  /**
   * 证件号码是否正确
   *
   * @param s
   * @return
   */
  public static boolean isIDCode(String s) {
    Matcher m = ID_CODE_PATTERN.matcher(s);
    return m.matches();
  }
  /**
   * 编码是否正确
   *
   * @param s
   * @return
   */
  public static boolean isCode(String s) {
    Matcher m = CODE_PATTERN.matcher(s);
    return m.matches();
  }
  /**
   * 固话编码是否正确
   *
   * @param s
   * @return
   */
  public static boolean isPhoneNumber(String s) {
    Matcher m = PHONE_NUMBER_PATTERN.matcher(s);
    return m.matches();
  }
  /**
   * 邮政编码是否正确
   *
   * @param s
   * @return
   */
  public static boolean isPostCode(String s) {
    Matcher m = POST_CODE_PATTERN.matcher(s);
    return m.matches();
  }
  /**
   * 面积是否正确
   *
   * @param s
   * @return
   */
  public static boolean isArea(String s) {
    Matcher m = AREA_PATTERN.matcher(s);
    return m.matches();
  }
  /**
   * 手机号码否正确
   *
   * @param s
   * @return
   */
  public static boolean isMobileNumber(String s) {
    Matcher m = MOBILE_NUMBER_PATTERN.matcher(s);
    return m.matches();
  }
  /**
   * 银行账号否正确
   *
   * @param s
   * @return
   */
  public static boolean isAccountNumber(String s) {
    Matcher m = ACCOUNT_NUMBER_PATTERN.matcher(s);
    return m.matches();
  }
}

以上是“Android开发中正则表达式工具类RegexUtil的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. Android开发中2个Xml合并的示例分析
  2. Android开发之系统管理工具类的示例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:Android中MIUI通知类短信权限的坑有哪些

下一篇:Android如何实现旋转、平移、缩放和透明度渐变的补间动画

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》