TheOne17 Posted March 5, 2007 Share Posted March 5, 2007 I have been using this function to validate an URL from field function checkURL($url) { return eregi("^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$", $url); } The only problem is that is won't accept URL's with a hyphen in e.g. www.northlincs.gov.uk/20-21 Does anyone know how to modify this to work with hyphens or have a good reg exp for URL's that will work with hyphens Thanks Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 5, 2007 Share Posted March 5, 2007 <?php $url="http://www.google.co.uk"; if(eregi("^(http://|https://|ftp://| http://www.)+[a-z0-9\_\-]{1,25}\.+ ([a-z0-9\_\-]{1,3}|.+[a-z0-9\_\-]{1,3}\. +[a-z0-9\_\-]{1,3})$", $url) ){ echo" your url is: $url"; }else{ echo"sorry wrong url: $url format"; } ?> This will do what ever but only for the index of the domain not what your trying to do if you want to your need to alter the code and add another or | ok. Quote Link to comment Share on other sites More sharing options...
effigy Posted March 5, 2007 Share Posted March 5, 2007 You can find more methods by searching for "http ftp" in the Regular Expressions board. Quote Link to comment Share on other sites More sharing options...
TheOne17 Posted March 5, 2007 Author Share Posted March 5, 2007 Thanks guys, Got this sorted with your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.