file name constraint in form
Per Clive's comment above, it works with this:   

        namespace Drupal\custom_validation\Plugin\Validation\Constraint;

        use Symfony\Component\Validator\Constraint;
        use Symfony\Component\Validator\ConstraintValidator;

        /**
         * Validates the Image constraint.
         */
        class MainImageConstraintValidator extends ConstraintValidator {

          /**
           * {@inheritdoc}
           */
          public function validate($items, Constraint $constraint) {
            foreach ($items as $item) {   
              if (strpos($item-&gt;entity-&gt;filename-&gt;value, 'shutterstock') !== false) {
                $this-&gt;context-&gt;addViolation($constraint-&gt;wrongImageName, ['%value' =&gt; $item-&gt;value]);
              }

            }
          }

        }