javascript Regex for Absolute AND relative URl -
is there regex validate both absolute url , relateve url javascript.
i have next regex works absolute url except part making http part mandatory. want optional.
here regex:
/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
thanks
quick answer, modified arun's reply take '/page', '/page/subpage', 'page/subpage'
/(\/?[\w-]+)(\/[\w-]+)*\/?|(((http|ftp|https):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?)/gi
but in actually, validate url regexp never esay. lots of border case, './page', '../page' etc.
analyse requirement carefully, write downwards major test cases, write regexp pass them all. , careful performance.
javascript regex validation url-validation
No comments:
Post a Comment