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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM