正则表达式 - 邮箱格式等

public static boolean isEmailOK(String ... email) {
    String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    Pattern p = Pattern.compile(regEx1);
    if(email == null || email.length==0){
      return false;
    }
    for (int i = 0;i < email.length; i++) {
      Matcher m = p.matcher(email[i]);
      if(!m.matches()){
        return false;
      }
    }
    return true;
}

public static void main(String[] args) {
  String[] s = new String[]{"amy.wang@pernod-ricard.com"};
  System.out.println(isEmailOK(s));
}
 /*
   * 对手机号码进行校验
   * 中国移动:134(0-8)、135、136、137、138、139、1440(物联网)、147(上网卡)、148(物联网)、150、151、152、157、158、159、165(虚拟运营商)、170(3,5,6)(虚拟运营商)、172、178、182、183、184、187、188、195、197、198
   * 中国联通:130、131、132、1400(物联网)、145(上网卡)、146(物联网)、155、156、166、167(虚拟运营商)、170(4,7,8,9)(虚拟运营商)、171(虚拟运营商)、175、176、185、186、196
   * 中国电信:133、1349(卫星通信)、1410(物联网)、149(上网卡)、153、162(虚拟运营商)、170(0-2)(虚拟运营商)、173、174(00-05)(卫星通信)、177、180、181、189、190、191、193、199
   */
  public static boolean isMobile(String mobile) {
    String regex = "^((13[0-9])|(14[5|7|9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8}$";
    // 创建一个匹配模式
    Pattern p = Pattern.compile(regex);
    // 返回matcher对象
    Matcher m = p.matcher(mobile);
    //判断是否匹配指定的字符串
    return m.matches();
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值