CodeIgniter Forums
Function to verify URL? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Function to verify URL? (/showthread.php?tid=9616)



Function to verify URL? - El Forum - 07-01-2008

[eluser]the jan[/eluser]
Hi!

I've been looking through the docs for an easy way to verify if a URL entered into a form is valid but I can't find a function. I know about the Verification Class and it contains a way to validate email adresses:

Code:
$rules['email'] = "required|valid_email";

Is there such an easy way for URLs? Or do I have to write my own regex?

Thanks,
Jan


Function to verify URL? - El Forum - 07-02-2008

[eluser]Jamie Rumbelow[/eluser]
I'm sure CodeIgniter provides a function that does exactly this, but I've looked through the user guide and can't find any.


Function to verify URL? - El Forum - 07-02-2008

[eluser]xwero[/eluser]
Validating urls is a tricky thing because one sites allowed characters are not another ones allowed characters. An then you also have the different protocols, the possibility of subdomains or only the domain, the TLD that is extended once in a while. if you create a regex the only thing you are certain of is a list with protocols, if you are not allowing application protocols like skype://, the colon, the two forward slashes and that there has to be a full stop somewhere in the url.

Even if you do a page exists polling to the actual website it's possible it's a redirect or a logged-in-only page.

Basically you have to trust users when it comes to adding urls.