Validating urls with regex
Posted: Thu May 14, 2009 7:37 am
Hi
Have a regex I have been using for some time to validate urls. However have just come across a problem where it will not valid a certain type of url. Its using eregi and is as follows:
^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~\[\]])*$
This works on most urls I have encountered. For example http://www.abcaddress.de will validate. However this will not:
http://www.abc-address.de/index.php?id= ... 41c3c3e3e2
Initially I thought it was due to the square brackets being used so I added \[\] which had no effect although I suspect it will once the other part is fixed.
Can anyone shed any light on this? Or point me to a regex that will validate any type of url?
Many thanks
Have a regex I have been using for some time to validate urls. However have just come across a problem where it will not valid a certain type of url. Its using eregi and is as follows:
^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~\[\]])*$
This works on most urls I have encountered. For example http://www.abcaddress.de will validate. However this will not:
http://www.abc-address.de/index.php?id= ... 41c3c3e3e2
Initially I thought it was due to the square brackets being used so I added \[\] which had no effect although I suspect it will once the other part is fixed.
Can anyone shed any light on this? Or point me to a regex that will validate any type of url?
Many thanks