js正则表达式判断url是否正确

通过正则表达式判断URL是否合法

判断是否是淘宝的网址

function testUrl(url) {
        let match2 = /^((http|https):\/\/)+([\w\-])+\.(tmall|taobao).com/;
        let testVol = match2.test(url);
        return testVol;
    }
    console.log(testUrl(url2));

判断url是否合法的正则表达式,包括地址带.cn

let match2 = /^((http|https):\/\/)?(([A-Za-z0-9]+-[A-Za-z0-9]+|[A-Za-z0-9]+)\.)+([A-Za-z]+)[/\?\:]?.*$/;

    let url1 = 'https://www.taobao.com/?spm=2013.1.0.0.a7423a1di051yg'
    let url3 = 'https://www.nju.edu.cn/'

    let vol2 = match2.test(url1);
    console.log(vol2);

 

其它可以参考:https://blog.csdn.net/altaba/article/details/78539752

       https://www.cnblogs.com/kenshinobiy/p/4655301.html

       https://blog.csdn.net/iteye_4856/article/details/81685377

 

posted @ 2020-09-23 16:15  云悠  阅读(8931)  评论(0编辑  收藏  举报