title: javascript/typescript | class-validator | custom validation decorators | override the `validationOptions` inside the `validator` method
body: <p>Consider the example provided in section <a href="https://github.com/typestack/class-validator#custom-validation-decorators" rel="nofollow noreferrer">Custom validation decorators</a>:</p>
  <pre class="lang-js prettyprint-override"><code>// Decorator definition
  
  
  import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator';
  
  export function IsLongerThan(property: string, validationOptions?: ValidationOptions) {
    return function (object: Object, propertyName: string) {
      registerDecorator({
        name: 'isLongerThan',
        target: object.constructor,
        propertyName: propertyName,
        constraints: [property],
        options: validationOptions,
        validator: {
          validate(value: any, args: ValidationArguments) {
            const [relatedPropertyName] = args.constraints;
            const relatedValue = (args.object as any)[relatedPropertyName];
            return typeof value === 'string' &amp;&amp; typeof relatedValue === 'string' &amp;&amp; value.length &gt; relatedValue.length; // you can return a Promise&lt;boolean&gt; here as well, if you want to make async validation
          },
        },
      });
    };
  }
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// Decorator usage
  
  
  import { IsLongerThan } from './IsLongerThan';
  
  export class Post {
    title: string;
  
    @IsLongerThan('title', {
      /* you can also use additional validation options, like &quot;groups&quot; in your custom validation decorators. &quot;each&quot; is not supported */
      message: 'Text must be longer than the title',
    })
    text: string;
  }
  </code></pre>
  <p>How can I set/override the <code>message</code> string conditionally, inside the <code>validator</code> method? Is this possible?</p>