code: public function createService(ServiceLocatorInterface $serviceLocator)
      {
          $services = $serviceLocator->getServiceLocator();
          /* @var $options InputFilterOptionsInterface */
          $options = $services->get(ModuleOptions::class);
  
          $validator = new ValidatorChain();
          $validator->setPluginManager($serviceLocator);
  
          $validator->attachByName('StringLength', [
              'messages' => [
                  StringLength::TOO_SHORT => 'The username must be at least %min% characters long',
                  StringLength::TOO_LONG => 'The username must not be more than %max% characters',
              ],
              'encoding' => 'UTF-8',
              'min' => 5,
              'max' => 30,
          ], true);
  
          $validator->attachByName('Regex', [
              'messages' => [
                  Regex::NOT_MATCH => 'Incorrect username. ' .
                      'Username must contain alphanumeric characters without spaces',
              ],
              'pattern' => $options->getUsernameRegexPattern(),
          ], true);
  
          $validator->attachByName('CmsUserNoUsernameExists', [], true);
  
          return $validator;
      }
docs: {@inheritDoc}
  
  @return ValidatorInterface