在输入框中如何判断输入的是一个正确的网址

let str = "https://www.baidu.com/index.php?tn=78040160_5_pg&ch=12#video"
let reg = /^(?:(http|https|ftp):\/\/)?((?:[\w-]+\.)+[a-z0-9]+)((?:\/[^/?#]*)+)?(\?[^#]+)?(#.+)?$/i;
console.log(reg.exec(str));
/**
   1、URL格式
      协议
      域名
    请问路径
    问号传参
     哈希值
**/
posted @ 2020-04-01 15:15  YuTing-721  阅读(815)  评论(0编辑  收藏  举报