Is there any regex which will validate both an absolute URL and relateve URl for Javascript.
I do have following Regex which works fairly well for absolute URL except the part where it is making the HTTP part mandatory. I want it optional.
Here is Regex:
/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
thanks
This one accepts things like:
But not things like
The regexp is:
Try
It makes the
(http|ftp|https):\/\/
(http://) portion optionalquick answer, modified Arun's answer to accept '/page', '/page/subpage', 'page/subpage'
but in actually, validate the url with RegExp is never esay. lots of edge case, like './page', '../page' etc.
analyse your requirement carefully, write down the major test cases, write a RegExp pass them all. and be careful with performance.