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

相关文章:

  • 2021-11-10
  • 2021-06-06
  • 2021-05-21
  • 2022-12-23
  • 2021-11-17
  • 2021-08-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2021-05-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案