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
https://forums.phpfreaks.com/topic/55439-solved-validating-local-urls/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.