通過正則表達式判斷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