校驗 url 是否以http 或者https 開頭


  1. var reUrl01 = /^((ht|f)tps?):\/\/([\w-]+(\.[\w-]+)*\/?)+(\?([\w\-\.,@?^=%&:\/~\+#]*)+)?$/;

  1. var reUrl01 = /^((ht|f)tps?):\/\/([\w-]+(\.[\w-]+)*\/?)+(\?([\w\-\.,@?^=%&:\/~\+#]*)+)?$/;

  2. //(1)、直接匹配域名地址:

  3. var matchString1 = 'https://www.jsdaxue.com';

  4. console.log(reUrl01.test(matchString1)); // ==> true

  5.  

  6. var matchString2 = 'https://www.jsdaxue.com/';

  7. console.log(reUrl01.test(matchString2)); // ==> true

  8.  

  9. var matchString3 = 'https://www.jsdaxue.com//'; // ==> 不允許非域名或參數以外的地方出現雙“/”;

  10. console.log(reUrl01.test(matchString3)); // ==> false

  11. //(2)、匹配鏈接含(*.htm,*.html,*.php,*.aspx...)后綴的地址:

  12. var matchString4 = 'https://www.jsdaxue.com/EditPosts.aspx';

  13. console.log(reUrl01.test(matchString4)); // ==> true

  14.  

  15. var matchString5 = 'https://www.jsdaxue.com./EditPosts.aspx'; // ==> 不允許參數以外的地方以雙“.”結尾;

  16. console.log(reUrl01.test(matchString5)); // ==> false

 

 

轉載 http://www.jsdaxue.com/archives/183.html


免責聲明!

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



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