javascript判断URL地址是否合法
function checkeURL(URL){ var str=URL; //在JavaScript中,正则表达式只能使用"/"开头和结束,不能使用双引号 //判断URL地址的正则表达式为:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)? //下面的代码中应用了转义字符"\"输出一个字符"/" var Expression=/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; var objExp=new RegExp(Expression); if(str.indexOf("localhost")){ str = str.replace("localhost","127.0.0.1"); } if(objExp.test(str)==true){ return true; }else{ return false; } }
相关推荐
AHuqihua 2020-06-14
86193952 2020-10-27
小木兮子 2020-11-11
HeyShHeyou 2020-11-17
seanzed 2020-10-15
huangliuyu00 2020-09-24
libaoshan 2020-09-11
zhangpan 2020-09-10
chongxiaocheng 2020-08-16
xcguoyu 2020-08-15
Qizonghui 2020-08-02
ldcwang 2020-07-26
mqfcu 2020-07-21
jeason 2020-07-20
sunzhihaofuture 2020-07-19
knightwatch 2020-07-19
点滴技术生活 2020-07-19
Reiki 2020-07-06