Validate CCK field to not allow links/URLs I want to allow users to input free text, but don't want them including any links or references to URLs. I know how to set up a filter on the CCK field so that 'a' tags cannot be included, but this will not stop the user typing www.google.com etc.

I have tried searching for modules to achieve this, but have not managed to find any. Does anyone know of a module to filter CCK fields to validate for 'www', '.com' etc, or alternatively one for custom CCK validation?

If there aren't any modules I think I would have to follow these instructions to build a custom CCK Validation module. I would appreciate advice on whether this would be the most efficient approach or if this would be reinventing the wheel?
Ok, So I have worked out how to do this.

First install the Field validation module.

Then go to the 'manage fields' page for your content type. To the right of each field is a 'validate' link. Click on validate for the field you wish to add validation for.

Click 'PHP code' and note the 'Be careful, it is powerful and also dangerous.' warning!

Enter a rule name such as 'dont allow URLs'.

In the PHP code box enter the php you wish to validate. I made an array of all the the top level domains etc I didn't want users to use, and checked the input against this in a foreach loop. The code I used to do this is:

$mystring = $this-&gt;value;
$arr = array("http", "https", "www", ".com", ".org", ".net", ".info", ".mil", ".mobi", ".edu", ".gov",  ".biz", ".ac", ".ad", ".ae", ".af", ".ai", ".al", ".am", ".ao", ".aq", ".ar", ".as", ".at", ".au", ".aw", ".ax", ".az", ".ba", ".bb", ".bd", ".be", ".bf", ".bg", ".bh", ".bi", ".bj", ".bm", ".bn", ".bo", ".br", ".bs", ".bt", ".bw", ".by", ".bz", ".ca", ".cc", ".cd", ".cf", ".cg", ".ch", ".ci", ".ck", ".cl", ".cm", ".cn", ".co", ".cr", ".cu", ".cv", ".cw", ".cx", ".cy", ".cz", ".de", ".dj", ".dk", ".dm", ".do", ".dz", ".ec", ".ee", ".eg", ".er", ".es", ".et", ".eu", ".fi", ".fj", ".fk", ".fm", ".fo", ".fr", ".ga", ".gd", ".ge", ".gf", ".gg", ".gh", ".gi", ".gl", ".gm", ".gn", ".gp", ".gq", ".gr", ".gs", ".gt", ".gu", ".gw", ".gy", ".hk", ".hm", ".hn", ".hr", ".ht", ".hu", ".id", ".ie", ".il", ".im", ".in", ".io", ".iq", ".ir", ".is", ".it", ".je", ".jm", ".jo", ".jp", ".ke", ".kg", ".kh", ".ki", ".km", ".kn", ".kp", ".kr", ".kw", ".ky", ".kz", ".la", ".lb", ".lc", ".li", ".lk", ".lr", ".ls", ".lt", ".lu", ".lv", ".ly", ".ma", ".mc", ".md", ".me", ".mh", ".mk", ".ml", ".mn", ".mo", ".mp", ".mq", ".mr", ".ms", ".mt", ".mu", ".mv", ".mw", ".mx", ".my", ".mz", ".na", ".nc", ".ne", ".nf", ".ng", ".ni", ".nl", ".no", ".np", ".nr", ".nu", ".nz", ".om", ".pa", ".pe", ".pf", ".pg", ".ph", ".pk", ".pl", ".pm", ".pn", ".pr", ".ps", ".pt", ".pw", ".py", ".qa", ".re", ".ro", ".rs", ".ru", ".rw", ".sa", ".sb", ".sc", ".sd", ".se", ".sg", ".sh", ".si", ".sk", ".sl", ".sm", ".sn", ".sp", ".sr", ".ss", ".st", ".sv", ".su", ".sx", ".sy", ".sz", ".tc", ".td", ".tf", ".tg", ".th", ".tj", ".tk", ".tl", ".tm", ".tn", ".to", ".tr", ".tt", ".tv", ".tw", ".tz", ".ua", ".ug", ".uk", ".us", ".uy", ".uz", ".va", ".vc", ".ve", ".vg", ".vi", ".vn", ".vu", ".wf", ".ws", ".ye", ".za", ".zm", ".zw", ".name", ".pro", ".aero", ".asia", ".cat", ".coop", ".jobs", ".museum", ".tel", ".travel");
    foreach ($arr as &amp;$findme) {
           $value = strpos($mystring, $findme);
           if ($value === false) {
           } else {
               $this-&gt;set_error();
           }
    }


Check the tick box that says 'Set errors using field API' 

In the last text box you add your custom error message. E.g. 

Please remove all links/URLs for example: 'www', '.co.uk'&amp; '.com'. Please check that you have a space after each full stop.


I hope that this helps somebody else.