Jump to content

[SOLVED] Validating local URLS


gijew

Recommended Posts

I'm hoping someone can help me out with this regular expression. I've been modifying this for about an hour and have only managed to validate the first part (being the http://localhost). I'm not super with regex so I could really use a hand and getting this to validate here..

 

What I'm attempting at doing is validate the following.

http://localhost/ [PASS]

http://localhost/page.html [PASS]

http://localhost/page.php?A=1 [PASS]

http://www.site.com [FAIL]

 

^((ht|f)tp://)((([a-z0-9-]+(\.))|(([0-9]{1,3}\.){3}([0-9]{1,3})))((/|\?)[a-zA-Z0-9~#%&'_\+=:\?\.-]*)*)$

 

Yes, I am trying to validate URLS so either a localhost or IP address will pass. There is also the page | directory / extension + any queries.

 

I would really appreciate your kind help here. Thank you!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.