js用正则判断 一个链接是否有效

  if ($('input[name="iIsRedirect"]').prop('checked') && p2['sRedirectURL'] != '') {
            var sRedirectURL = $('input[name="sRedirectURL"]').val(),
                reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;   //正则表达式判断http://    https://  为合法

                objExp = new RegExp(reg);


            if (objExp.test(sRedirectURL) != true) {
                layer.alert('跳转地址不正确!');
                return;
            }


        }

 reg = /^(http:\/\/|^https:\/\/|^\/\/)((\w|=|\?|\.|\/|&|-)+)/g; //正则表达式判断http://    https://     //   开头都为合法

此方法判断 获取到的一个url跟正则匹配 是否是有效地址

猜你喜欢

转载自blog.csdn.net/dxj124/article/details/79003882