判断电话号码以及邮箱正确性的正则表达式

参考链接:

java函数

/**
      * 验证邮箱地址是否正确
      * @param email
      * @return
      */
     public static boolean checkEmail(String email){
      boolean flag = false;
      try{
       String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
       Pattern regex = Pattern.compile(check);
       Matcher matcher = regex.matcher(email);
       flag = matcher.matches();
      }catch(Exception e){
       //LOG.error("验证邮箱地址错误", e);
       flag = false;
      }
      
      return flag;
     }
     /**
      * 验证手机号码
      * @param mobiles
      * @return
      */
     public static boolean isMobileNO(String mobiles){
      boolean flag = false;
      try{
       Pattern p = Pattern.compile("^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}$");
       Matcher m = p.matcher(mobiles);
       flag = m.matches();
      }catch(Exception e){
       //LOG.error("验证手机号码错误", e);
       flag = false;
      }
      return flag;
     }

js正则表达式(参考链接:http://caibaojian.com/regexp-example.html)

function checkPhone(){   //电话号码
    var phone = document.getElementById('phone').value;
    if(!(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}/.test(phone)))
  {
    alert(
"手机号码有误,请重填"); return false;
  }
}
function checkTel(){  //固定电话
 var tel = document.getElementById('tel').value;
if(!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(tel)){
alert('固定电话有误,请重填');
return false;
}
}
//身份证正则表达式(18位)
isIDCard2=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;

其他

提取信息中的网络链接:(h|H)(r|R)(e|E)(f|F) *= *('|")?(\w|\\|\/|\.)+('|"| *|>)?
提取信息中的邮件地址:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
提取信息中的图片链接:(s|S)(r|R)(c|C) *= *('|")?(\w|\\|\/|\.)+('|"| *|>)?
提取信息中的IP地址:(\d+)\.(\d+)\.(\d+)\.(\d+)
提取信息中的中国电话号码(包括移动和固定电话):(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}
提取信息中的中国邮政编码:[1-9]{1}(\d+){5}
提取信息中的中国身份证号码:\d{18}|\d{15}
提取信息中的整数:\d+
提取信息中的浮点数(即小数):(-?\d*)\.?\d+
提取信息中的任何数字 :(-?\d*)(\.\d+)?
提取信息中的中文字符串:[\u4e00-\u9fa5]*
提取信息中的双字节字符串 (汉字):[^\x00-\xff]*

猜你喜欢

转载自www.cnblogs.com/1gaoyu/p/11729066.html
今日推荐