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