# Custom validators with parameters

**URL:** <https://discourse.laminas.dev/t/custom-validators-with-parameters/2502>\
**Category:** API Tools\
**Created:** [September 15, 2021, 12:50pm UTC](https://discourse.laminas.dev/t/custom-validators-with-parameters/2502 "2021-09-15T12:50:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Admirau](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/admirau/32/823_2.png) [@Admirau](https://discourse.laminas.dev/u/Admirau)\
**Post date:** [September 15, 2021, 12:50pm UTC](https://discourse.laminas.dev/t/custom-validators-with-parameters/2502/1 "2021-09-15T12:50:18Z")

</div>

How can I add custom validators with parameters in API Tools GUI?

I wrote a custom validator + factory.

I have some setters+getters there.

How can I configure this validator the way it would:

- show up in the list of available validators in the GUI (I’m adding a factory to `validators.factories` key in the `module.config.php`
- allow the user to choose parameters (eg. `maxlen`, `minlen` etc.). Now it shows only one option available: `breakchainonfailure`

Similar to the StringLength validator:

![Options](https://i.imgur.com/dhUnD89.png)

My factory:

```auto
<?php

namespace My\Validator\DoctrineConnected\Factory;

use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\ServiceManager\Factory\AbstractFactoryInterface;

class ExistsValidatorFactory implements AbstractFactoryInterface {
    /**
     * Create an object
     *
     * @param ContainerInterface $container
     * @param string $requestedName
     * @param null|array $options
     * @return object
     * @throws ServiceNotFoundException if unable to resolve the service.
     * @throws ServiceNotCreatedException if an exception is raised when
     * creating a service.
     * @throws ContainerException if any other error occurs
     */
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null) {
        $entityManger = $container->get('doctrine.entitymanger.orm_default');
        return new $requestedName($entityManger);
    }

    public function canCreate(ContainerInterface $container, $requestedName)
    {
        return class_exists($requestedName);
    }
}

```
