title: How to pass parameters to a custom validator in Sitecore
body: <p>I have a custom validator class to validate a <code>General Link</code> field type. It checks that the field value of the <code>Description</code> field is not more than 15 characters.<br>
  But what if a Link field of same or another template, requires 20 chars.    </p>
  
  <p>Is there a way, I can pass the integer as a parameter. If so, how to pass &amp; use it.<br>
  Also, can it be done at the base Template's field level. (so that I can define limits for each such field)</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace CustomValidators
  {
    // This validator ensures that the description attribute of a link is either empty or has length of 15 characters.
    [Serializable]
    public class LinkTextValidator : StandardValidator
    {
      public override string Name {get { return "Link text validator"; } }
  
      public LinkTextValidator() { }
  
      public LinkTextValidator(SerializationInfo info, StreamingContext context) : base(info, context) { }
  
      protected override ValidatorResult Evaluate()
      {
        Field field = this.GetField();
  
        if (field == null)
          return ValidatorResult.Valid;
  
        string fieldValue = this.ControlValidationValue;
  
        if (string.IsNullOrEmpty(fieldValue) || string.Compare(fieldValue, "&lt;link&gt;", StringComparison.InvariantCulture) == 0)
           return ValidatorResult.Valid;
  
        XmlValue xmlValue = new XmlValue(fieldValue, "link");
        string attribute = xmlValue.GetAttribute("text");
  
        if (!string.IsNullOrEmpty(xmlValue.GetAttribute("text")) &amp;&amp; Convert.ToString(xmlValue.GetAttribute("text")).Length &gt; 15)
        {
          this.Text = this.GetText("Description field should have not more than 15 characters, in the link field \"{0}\".", field.DisplayName);
          return this.GetFailedResult(ValidatorResult.FatalError);
        }
        else
        {
          return ValidatorResult.Valid;
        }
       }
  
      protected override ValidatorResult GetMaxValidatorResult()
      {
        return this.GetFailedResult(ValidatorResult.FatalError);
      }
     }
  }
  </code></pre>