hi, i am creating a form of which will update portfolios, included is a text field...i already have blocked the usage of html and email addresses from being posted, but i cant seem to figure out how i would block website addresses?

what code would i use to do this? what would be the best to block? www or .com .co.uk etc?

Member Avatar for diafol

Have a look at regular expressions / preg_match and how to identify a valid url. It's more complicated that you might think. Simply looking for http://, https://, mms://, ftp:// etc won't be enough. 'www' isn't always required for a url. subdomains exist too. Millions of TLDs. What about querystrings and username/passwords? Just given myself a nosebleed.

you can use this function to block www links

function isValidURL($url)
{
return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}

if(isValidURL($fldbanner_url))
{
$errMsg .= "* Please enter valid URL including http://<br>";
}

i am trying this code but i have errors...

$reg="/[\s]*[a-zA-Z0-9_.%+-]+(.uk|com|.php|.aero|.asia|.biz|.cat|.coop|.edu|.gov|.info|.int|.jobs|.mil|.mobi|.museum|.name|.net|.org|.pro|.tel|.travel|.co|.ly|.htm|.html|.tk|.jsp|.shtml|.dhtml|.cc)/";

the problem im having is that its not blocking .com or .co.uk .org etc, but its blocking everytime i use the letters...so if i type comma , it blocks it!
i figured using the . infront it would only block .com etc...but that doesnt seem to be working...any ideas how i would only look for .com .co .or etc??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.