What is regexp to validate relative url ?
In this link
On above link , for relative url : (/[\w~,;\-\./?%&+#=]*)
i edit for validate
var pattern = '/\/[^\w~,;\-\.\/?%&+#=]*/i';
if (!link.match(new RegExp(/\/[^\w~,;\-\.\/?%&+#=]*/i)))
{
alert('invalid relative link');
}
Did i wrong ? how to 开发者_运维技巧validate both absolute & relative link ?
the reality is anything is a valid relative URL in general! In the context of website http://abc.com for instance, a is a relative url and it expands to http://abc.com/a; 23$rt% is just as valid and it expands to http://abc.com/23$rt% ! If you mean whether you want to check if the link exists that I suppose you need to employ some Ajax code to assemble the full url and try to fetch it in the background and check the error code (e.g. 200 OK means the url is good, 404 is not found etc).
精彩评论