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

源码网商城

Android编程开发中的正则匹配操作示例

  • 时间:2022-05-28 12:26 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android编程开发中的正则匹配操作示例
本文实例讲述了Android编程开发中的正则匹配操作。分享给大家供大家参考,具体如下: 在Android开发中,可能也会遇到一下输入框的合法性验证,这时候最常用的就应该是正则表达式去做一些匹配了,下面就常用的正则匹配做一下介绍 [b]1. 手机号码的验证[/b] 根据实际开发于2009年9月7日最新统计: 中国电信发布中国3G号码段:中国联通185,186;中国移动188,187;中国电信189,180共6个号段。 移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188 联通:130、131、132、152、155、156、185、186 电信:133、153、180、189、(1349卫通) 匹配代码(目前,号码段可能添加了一下,大家根据实际情况写正则表达式)
public class ClassPathResource {
 private static final Logger logger = Logger.getLogger(ClassPathResource.class);
  public static boolean isMobileNO(String mobiles){
    Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
    Matcher m = p.matcher(mobiles);
    logger.info(m.matches()+"---");
    return m.matches();
  }

[b]2.邮件的验证[/b]
public static boolean isEmail(String email){
String str="^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$";
  Pattern p = Pattern.compile(str);
  Matcher m = p.matcher(email);
  logger.info(m.matches()+"---");
  return m.matches();

[b]3.IP地址的验证[/b]
Pattern pattern = Pattern.compile("");
Matcher matcher = pattern.matcher("127.400.600.2"); //以验证127.400.600.2为例
System.out.println(matcher.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
微信版

扫一扫进微信版
返回顶部