校验 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