regex for URL validation
Posted: Tue Jun 29, 2010 9:44 am
hey folks!
i got this regex:
and its cool for regular urls, but it wont accept a slash at the end, or even slash something, like http://www.example.com/index.php
any clues how to add support to that?
the regex i really wanted is like this:
(http(s):// or ftp://) [here could be letters, numbers, dots, dashes, slashes, etc] dot [here would accept letters only, 2 or 3 digits for endings like com, co, net, it, tk]{i dont know if numbers are needed, i've only seen extensions with 2 or 3 characters, and no numbers, please correct me}[and anything again, like whatever can come after the .com, .co .net, could be anything like extension.php?variable=value]
hope i make myself clear enough!
thanks in advance people
i got this regex:
Code: Select all
preg_match("/^(http(s?):\/\/|ftp:\/\/{1})((\w+\.){1,})\w{2,}$/i", $urlany clues how to add support to that?
the regex i really wanted is like this:
(http(s):// or ftp://) [here could be letters, numbers, dots, dashes, slashes, etc] dot [here would accept letters only, 2 or 3 digits for endings like com, co, net, it, tk]{i dont know if numbers are needed, i've only seen extensions with 2 or 3 characters, and no numbers, please correct me}[and anything again, like whatever can come after the .com, .co .net, could be anything like extension.php?variable=value]
hope i make myself clear enough!
thanks in advance people