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


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);

$errMsg .= "* Please enter valid URL including http://<br>";

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


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??