Ludatha
02-04-2009, 03:56 PM
Hey guys, I am trying to get a perfect regex that validates a url, but I cannot seem to find one.
The best one I have is this:
preg_match("/^(http(s?):\\/\\/|ftp:\\/\\/{1})((\w+\.)+)\w{2,}(\/?)$/i", $_POST['url'])
But it doesnt validate a url like this:
http://forums.digitalpoint.com/showthread.php?t=1215701#post10533297
You cannot have anything after the .com
I need it to support directories:
http://www.ludatha.com/user/
Files:
http://www.ludatha.com/user.php
_GET Variables
http://www.ludatha.com/user.php?id=Adam
Anchors
http://www.ludatha.com/user.php?id=Adam#comments
Can anyone find me or code me one that works ?
Thanks
The best one I have is this:
preg_match("/^(http(s?):\\/\\/|ftp:\\/\\/{1})((\w+\.)+)\w{2,}(\/?)$/i", $_POST['url'])
But it doesnt validate a url like this:
http://forums.digitalpoint.com/showthread.php?t=1215701#post10533297
You cannot have anything after the .com
I need it to support directories:
http://www.ludatha.com/user/
Files:
http://www.ludatha.com/user.php
_GET Variables
http://www.ludatha.com/user.php?id=Adam
Anchors
http://www.ludatha.com/user.php?id=Adam#comments
Can anyone find me or code me one that works ?
Thanks