0

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 ?

0

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.