源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-03-15 16:14 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android开发中超好用的正则表达式工具类RegexUtil完整实例
本文实例讲述了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();
  }
}

[b]PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:[/b] [b]JavaScript正则表达式在线测试工具: [/b][url=http://tools.jb51.net/regex/javascript]http://tools.jb51.net/regex/javascript[/url] [b]正则表达式在线生成工具: [/b][url=http://tools.jb51.net/regex/create_reg]http://tools.jb51.net/regex/create_reg[/url] 更多关于Android相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/124.htm]Android控件用法总结[/url]》、《[url=http://www.1sucai.cn/Special/410.htm]Android开发入门与进阶教程[/url]》、《[url=http://www.1sucai.cn/Special/375.htm]Android视图View技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/367.htm]Android编程之activity操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/402.htm]Android数据库操作技巧总结[/url]》及《[url=http://www.1sucai.cn/Special/423.htm]Android资源操作技巧汇总[/url]》 希望本文所述对大家Android程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部