Adding custom validation to core fields I've been looking at http://straightupcraft.com/articles/the-definitive-guide-to-validation-in-craft which seems to concentrate on custom models. However I am looking to validate data posted to a plugin that stores that data as core EntryModels.

So let's say you create a Section and assign some Fields in its field layout. You can set each Field to be required but I want to do more than that and check if it's an integer or if it's unique.

I am currently doing that in my service class:

private function validateReference()
{
    $reference = craft()-&gt;request-&gt;getPost('reference');

    $existingEntryCount = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry)-&gt;total(array(
        'reference' =&gt; $reference
    ));

    return ($existingEntryCount === 0);
}


That all works but I am wondering if instead I should be setting the validation properties of each Field in this service and then just running a core validate method?
Your best bet is going to be to write your own field type for this. You can extend one of the built-in field types if you want.

You would put your custom validation logic in your field type’s validate() method.