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

posted @ 2019-12-16 16:13  1点  阅读(5351)  评论(0编辑  收藏  举报