判斷電話號碼以及郵箱正確性的正則表達式


參考鏈接:

 

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]*

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM