<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>FluentValidation Wiki &amp; Documentation Rss Feed</title><link>http://www.codeplex.com/FluentValidation/Wiki/View.aspx?title=Home</link><description>FluentValidation Wiki Rss Description</description><item><title>Updated Wiki: Customising</title><link>https://fluentvalidation.codeplex.com/wikipage?title=Customising&amp;version=15</link><description>&lt;div class="wikidoc"&gt;&lt;a name="CustomError"&gt;&lt;/a&gt;
&lt;h2&gt;Overriding the Default Error&lt;/h2&gt;You can override the default error message for a validator by calling the &lt;b&gt;WithMessage&lt;/b&gt; method on a validator definition:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithMessage(&amp;quot;Please ensure that you have entered your Surname&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that custom error messages can contain placeholders for special values such as the name of the property being validated. This means the above error message could be re-written as:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithMessage(&amp;quot;Please ensure you have entered your {PropertyName}&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...and the value &amp;#39;Surname&amp;#39; will be inserted. For a complete list of error message placeholders see the &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Customising"&gt;Validators&lt;/a&gt; page. &lt;br /&gt;&lt;br /&gt;It is also possible to use your own custom arguments in the validation message. These can either be static values or references to other properties on the object being validated:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
//Using static values in a custom message:
RuleFor(customer =&amp;gt; x.Surname).NotNull().WithMessage(&amp;quot;This message references some static values: {0} {1}&amp;quot;, &amp;quot;hello&amp;quot;, 5);
//Result would be &amp;quot;This message references some static values: hello 5&amp;quot;

//Referencing other property values:
RuleFor(customer =&amp;gt; customer.Surname)
  .NotNull()
  .WithMesasge(&amp;quot;This message references some other properties: Forename: {0} Discount: {1}&amp;quot;, 
    customer =&amp;gt; customer.Forename, 
    customer =&amp;gt; customer.Discount
  );
//Result would be: &amp;quot;This message references some other properties: Forename: Jeremy Discount: 100&amp;quot;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you want to override all of FluentValidation&amp;#39;s default error messages, check out FluentValidation&amp;#39;s support for &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Localization&amp;referringTitle=Customising"&gt;Localization&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a name="PropertyName"&gt;&lt;/a&gt;
&lt;h2&gt;Overriding the Default Property Name&lt;/h2&gt;The default validation error messages contain the property name being validated. For example, if you were to define a validator like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull();
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...then the default error message would be &lt;i&gt;&amp;#39;Surname&amp;#39; must not be empty.&lt;/i&gt; Although you can override the entire error message by calling &lt;b&gt;WithMessage&lt;/b&gt;, you can also replace just the property name by calling &lt;b&gt;WithName&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithName(&amp;quot;Last name&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now the error message would be &lt;i&gt;&amp;#39;Last name&amp;#39; must not be empty.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Note that this only replaces the name of the property in the error message. When you inspect the Errors collection on the ValidationResult, this error will still be associated with a property called &amp;quot;Surname&amp;quot;. If you want to completely rename the property, you can use the &lt;b&gt;WithPropertyName&lt;/b&gt; method instead.&lt;br /&gt;&lt;br /&gt;Property name resolution is also pluggable. By default, the name of the property extracted from the MemberExpression passed to RuleFor. If you want change this logic, you can set the PropertyNameResolver property on the ValidatorOptions class:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
ValidatorOptions.PropertyNameResolver = (type, member) =&amp;gt; {
  if(member != null) {
     return member.Name + &amp;quot;Foo&amp;quot;;
  }
  return null;
};
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is not a realistic example as it changes all properties to have the suffix &amp;quot;Foo&amp;quot;, but hopefully illustrates the point. &lt;br /&gt;&lt;br /&gt;Additionally, FluentValidation will respect the use of the DisplayName and Display attributes for generating the property&amp;#39;s name within error messages:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class Person {
  [Display(Name=&amp;quot;Last name&amp;quot;)]
  public string Surname { get; set; }
}
&lt;/pre&gt;&lt;br /&gt;&lt;a name="WhenUnless"&gt;&lt;/a&gt;
&lt;h2&gt;Specifying a condition with When/Unless&lt;/h2&gt;The &lt;b&gt;When&lt;/b&gt; and &lt;b&gt;Unless&lt;/b&gt; methods can be used to specify conditions that control when the rule should execute. For example, this rule on the CustomerDiscount property will only execute when IsPreferredCustomer is true:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.CustomerDiscount).GreaterThan(0).When(customer =&amp;gt; customer.IsPreferredCustomer);
&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Unless&lt;/b&gt; method is simply the opposite of &lt;b&gt;When&lt;/b&gt;. &lt;br /&gt;&lt;br /&gt;If you need to specify the same condition for multiple rules then you can call the top-level When method instead of chaining the When call at the end of the rule:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
When(customer =&amp;gt; customer.IsPreferred, () =&amp;gt; {
   RuleFor(customer =&amp;gt; customer.CustomerDiscount).GreaterThan(0);
   RuleFor(customer =&amp;gt; customer.CreditCardNumber).NotNull();
});
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This time, the condition will be applied to both rules. &lt;br /&gt;&lt;br /&gt;&lt;a name="Cascade"&gt;&lt;/a&gt;
&lt;h2&gt;Setting the Cascade mode&lt;/h2&gt;
You can set the cascade mode to customise how FluentValidation executes chained validators when a particular validator in the chain fails.&lt;br /&gt;&lt;br /&gt;Imagine you have two validators defined as part of a single rule definition, a NotNull validator and a NotEqual validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(x =&amp;gt; x.Surname).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This will first check whether the Surname property is not null and then will check if it&amp;#39;s not equal to the string &amp;quot;foo&amp;quot;. If the first validator (NotNull) fails, then the call to NotEqual will still be invoked. This can be changed by specifying a cascade mode of &lt;b&gt;StopOnFirstFailure&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(x =&amp;gt; x.Surname).Cascade(CascadeMode.StopOnFirstFailure).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, if the NotNull validator fails then the NotEqual validator will not be executed. This is particularly useful if you have a complex chain where each validator depends on the previous validator to succeed. &lt;br /&gt;&lt;br /&gt;The two cascade modes are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Continue (the default) - always invokes all validators in a rule definition&lt;/li&gt;
&lt;li&gt;StopOnFirstFailure - stops executing a rule as soon as a validator fails&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;As well as being set at the rule level, the cascade mode can also be set globally for all validators, or for all the rules in a particular validator class.&lt;br /&gt;&lt;br /&gt;To set the cascade mode globally, you can set the CascadeMode property on the static ValidatorOptions class during your application&amp;#39;s startup routine:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
ValidatorOptions.CascadeMode = CascadeMode.StopOnFirstFailure;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This can then be overriden by individual validator classes or by individual rules.&lt;br /&gt;&lt;br /&gt;To set the cascade mode for all rules inside a single validator class, set the CascadeMode property on AbstractValidator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class PersonValidator : AbstractValidator&amp;lt;Person&amp;gt; {
  public PersonValidator() {
    
    // First set the cascade mode
    CascadeMode = CascadeMode.StopOnFirstFailure;
    
    // Rule definitions follow
    RuleFor(...) 
    RuleFor(...)

   }
}
&lt;/pre&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Mon, 13 May 2013 16:02:37 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Customising 20130513040237P</guid></item><item><title>Updated Wiki: Customising</title><link>https://fluentvalidation.codeplex.com/wikipage?title=Customising&amp;version=14</link><description>&lt;div class="wikidoc"&gt;&lt;a name="CustomError"&gt;&lt;/a&gt;
&lt;h2&gt;Overriding the Default Error&lt;/h2&gt;You can override the default error message for a validator by calling the &lt;b&gt;WithMessage&lt;/b&gt; method on a validator definition:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithMessage(&amp;quot;Please ensure that you have entered your Surname&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that custom error messages can contain placeholders for special values such as the name of the property being validated. This means the above error message could be re-written as:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithMessage(&amp;quot;Please ensure you have entered your {PropertyName}&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...and the value &amp;#39;Surname&amp;#39; will be inserted. For a complete list of error message placeholders see the &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Customising"&gt;Validators&lt;/a&gt; page. &lt;br /&gt;&lt;br /&gt;It is also possible to use your own custom arguments in the validation message. These can either be static values or references to other properties on the object being validated:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
//Using static values in a custom message:
RuleFor(customer =&amp;gt; x.Surname).NotNull().WithMessage(&amp;quot;This message references some static values: {0} {1}&amp;quot;, &amp;quot;hello&amp;quot;, 5);
//Result would be &amp;quot;This message references some static values: hello 5&amp;quot;

//Referencing other property values:
RuleFor(customer =&amp;gt; customer.Surname)
  .NotNull()
  .WithMesasge(&amp;quot;This message references some other properties: Forename: {0} Discount: {1}&amp;quot;, 
    customer =&amp;gt; customer.Forename, 
    customer =&amp;gt; customer.Discount
  );
//Result would be: &amp;quot;This message references some other properties: Forename: Jeremy Discount: 100&amp;quot;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you want to override all of FluentValidation&amp;#39;s default error messages, check out FluentValidation&amp;#39;s support for &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Localization&amp;referringTitle=Customising"&gt;Localization&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a name="PropertyName"&gt;&lt;/a&gt;
&lt;h2&gt;Overriding the Default Property Name&lt;/h2&gt;The default validation error messages contain the property name being validated. For example, if you were to define a validator like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull();
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...then the default error message would be &lt;i&gt;&amp;#39;Surname&amp;#39; must not be empty.&lt;/i&gt; Although you can override the entire error message by calling &lt;b&gt;WithMessage&lt;/b&gt;, you can also replace just the property name by calling &lt;b&gt;WithName&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithName(&amp;quot;Last name&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now the error message would be &lt;i&gt;&amp;#39;Last name&amp;#39; must not be empty.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Note that this only replaces the name of the property in the error message. When you inspect the Errors collection on the ValidationResult, this error will still be associated with a property called &amp;quot;Surname&amp;quot;. If you want to completely rename the property, you can use the &lt;b&gt;WithPropertyName&lt;/b&gt; method instead.&lt;br /&gt;&lt;br /&gt;Property name resolution is also pluggable. By default, the name of the property extracted from the MemberExpression passed to RuleFor. If you want change this logic, you can set the PropertyNameResolver property on the ValidatorOptions class:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
ValidatorOptions.PropertyNameResolver = (type, member) =&amp;gt; {
  if(member != null) {
     return member.Name + &amp;quot;Foo&amp;quot;;
  }
  return null;
};
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is not a realistic example as it changes all properties to have the suffix &amp;quot;Foo&amp;quot;, but hopefully illustrates the point. &lt;br /&gt;&lt;br /&gt;Additionally, FluentValidation will respect the use of the DisplayName and Display attributes for generating the property&amp;#39;s name within error messages:&lt;br /&gt;&lt;br /&gt;{{&lt;br /&gt;public class Person {&lt;br /&gt;  [Display(Name=&amp;quot;Last name&amp;quot;)]&lt;br /&gt;  public string Surname { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;a name="WhenUnless"&gt;&lt;/a&gt;
&lt;h2&gt;Specifying a condition with When/Unless&lt;/h2&gt;The *When* and *Unless* methods can be used to specify conditions that control when the rule should execute. For example, this rule on the CustomerDiscount property will only execute when IsPreferredCustomer is true:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.CustomerDiscount).GreaterThan(0).When(customer =&amp;gt; customer.IsPreferredCustomer);
&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Unless&lt;/b&gt; method is simply the opposite of &lt;b&gt;When&lt;/b&gt;. &lt;br /&gt;&lt;br /&gt;If you need to specify the same condition for multiple rules then you can call the top-level When method instead of chaining the When call at the end of the rule:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
When(customer =&amp;gt; customer.IsPreferred, () =&amp;gt; {
   RuleFor(customer =&amp;gt; customer.CustomerDiscount).GreaterThan(0);
   RuleFor(customer =&amp;gt; customer.CreditCardNumber).NotNull();
});
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This time, the condition will be applied to both rules. &lt;br /&gt;&lt;br /&gt;&lt;a name="Cascade"&gt;&lt;/a&gt;
&lt;h2&gt;Setting the Cascade mode&lt;/h2&gt;
You can set the cascade mode to customise how FluentValidation executes chained validators when a particular validator in the chain fails.&lt;br /&gt;&lt;br /&gt;Imagine you have two validators defined as part of a single rule definition, a NotNull validator and a NotEqual validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(x =&amp;gt; x.Surname).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This will first check whether the Surname property is not null and then will check if it&amp;#39;s not equal to the string &amp;quot;foo&amp;quot;. If the first validator (NotNull) fails, then the call to NotEqual will still be invoked. This can be changed by specifying a cascade mode of &lt;b&gt;StopOnFirstFailure&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(x =&amp;gt; x.Surname).Cascade(CascadeMode.StopOnFirstFailure).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, if the NotNull validator fails then the NotEqual validator will not be executed. This is particularly useful if you have a complex chain where each validator depends on the previous validator to succeed. &lt;br /&gt;&lt;br /&gt;The two cascade modes are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Continue (the default) - always invokes all validators in a rule definition&lt;/li&gt;
&lt;li&gt;StopOnFirstFailure - stops executing a rule as soon as a validator fails&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;As well as being set at the rule level, the cascade mode can also be set globally for all validators, or for all the rules in a particular validator class.&lt;br /&gt;&lt;br /&gt;To set the cascade mode globally, you can set the CascadeMode property on the static ValidatorOptions class during your application&amp;#39;s startup routine:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
ValidatorOptions.CascadeMode = CascadeMode.StopOnFirstFailure;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This can then be overriden by individual validator classes or by individual rules.&lt;br /&gt;&lt;br /&gt;To set the cascade mode for all rules inside a single validator class, set the CascadeMode property on AbstractValidator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class PersonValidator : AbstractValidator&amp;lt;Person&amp;gt; {
  public PersonValidator() {
    
    // First set the cascade mode
    CascadeMode = CascadeMode.StopOnFirstFailure;
    
    // Rule definitions follow
    RuleFor(...) 
    RuleFor(...)

   }
}
&lt;/pre&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Mon, 13 May 2013 16:02:24 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Customising 20130513040224P</guid></item><item><title>Updated Wiki: Customising</title><link>https://fluentvalidation.codeplex.com/wikipage?title=Customising&amp;version=13</link><description>&lt;div class="wikidoc"&gt;&lt;a name="CustomError"&gt;&lt;/a&gt;
&lt;h2&gt;Overriding the Default Error&lt;/h2&gt;You can override the default error message for a validator by calling the &lt;b&gt;WithMessage&lt;/b&gt; method on a validator definition:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithMessage(&amp;quot;Please ensure that you have entered your Surname&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that custom error messages can contain placeholders for special values such as the name of the property being validated. This means the above error message could be re-written as:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithMessage(&amp;quot;Please ensure you have entered your {PropertyName}&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...and the value &amp;#39;Surname&amp;#39; will be inserted. For a complete list of error message placeholders see the &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Customising"&gt;Validators&lt;/a&gt; page. &lt;br /&gt;&lt;br /&gt;It is also possible to use your own custom arguments in the validation message. These can either be static values or references to other properties on the object being validated:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
//Using static values in a custom message:
RuleFor(customer =&amp;gt; x.Surname).NotNull().WithMessage(&amp;quot;This message references some static values: {0} {1}&amp;quot;, &amp;quot;hello&amp;quot;, 5);
//Result would be &amp;quot;This message references some static values: hello 5&amp;quot;

//Referencing other property values:
RuleFor(customer =&amp;gt; customer.Surname)
  .NotNull()
  .WithMesasge(&amp;quot;This message references some other properties: Forename: {0} Discount: {1}&amp;quot;, 
    customer =&amp;gt; customer.Forename, 
    customer =&amp;gt; customer.Discount
  );
//Result would be: &amp;quot;This message references some other properties: Forename: Jeremy Discount: 100&amp;quot;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you want to override all of FluentValidation&amp;#39;s default error messages, check out FluentValidation&amp;#39;s support for &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Localization&amp;referringTitle=Customising"&gt;Localization&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a name="PropertyName"&gt;&lt;/a&gt;
&lt;h2&gt;Overriding the Default Property Name&lt;/h2&gt;The default validation error messages contain the property name being validated. For example, if you were to define a validator like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull();
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...then the default error message would be &lt;i&gt;&amp;#39;Surname&amp;#39; must not be empty.&lt;/i&gt; Although you can override the entire error message by calling &lt;b&gt;WithMessage&lt;/b&gt;, you can also replace just the property name by calling &lt;b&gt;WithName&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithName(&amp;quot;Last name&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now the error message would be &lt;i&gt;&amp;#39;Last name&amp;#39; must not be empty.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Note that this only replaces the name of the property in the error message. When you inspect the Errors collection on the ValidationResult, this error will still be associated with a property called &amp;quot;Surname&amp;quot;. If you want to completely rename the property, you can use the &lt;b&gt;WithPropertyName&lt;/b&gt; method instead.&lt;br /&gt;&lt;br /&gt;Property name resolution is also pluggable. By default, the name of the property extracted from the MemberExpression passed to RuleFor. If you want change this logic, you can set the PropertyNameResolver property on the ValidatorOptions class:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
ValidatorOptions.PropertyNameResolver = (type, member) =&amp;gt; {
  if(member != null) {
     return member.Name + &amp;quot;Foo&amp;quot;;
  }
  return null;
};
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is not a realistic example as it changes all properties to have the suffix &amp;quot;Foo&amp;quot;, but hopefully illustrates the point. &lt;br /&gt;&lt;br /&gt;Additionally, FluentValidation will respect the use of the &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=DisplayName&amp;referringTitle=Customising"&gt;DisplayName&lt;/a&gt; and &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Display&amp;referringTitle=Customising"&gt;Display&lt;/a&gt; attributes for generating the property&amp;#39;s name within error messages.&lt;br /&gt;&lt;br /&gt;&lt;a name="WhenUnless"&gt;&lt;/a&gt;
&lt;h2&gt;Specifying a condition with When/Unless&lt;/h2&gt;The &lt;b&gt;When&lt;/b&gt; and &lt;b&gt;Unless&lt;/b&gt; methods can be used to specify conditions that control when the rule should execute. For example, this rule on the CustomerDiscount property will only execute when IsPreferredCustomer is true:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.CustomerDiscount).GreaterThan(0).When(customer =&amp;gt; customer.IsPreferredCustomer);
&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Unless&lt;/b&gt; method is simply the opposite of &lt;b&gt;When&lt;/b&gt;. &lt;br /&gt;&lt;br /&gt;If you need to specify the same condition for multiple rules then you can call the top-level When method instead of chaining the When call at the end of the rule:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
When(customer =&amp;gt; customer.IsPreferred, () =&amp;gt; {
   RuleFor(customer =&amp;gt; customer.CustomerDiscount).GreaterThan(0);
   RuleFor(customer =&amp;gt; customer.CreditCardNumber).NotNull();
});
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This time, the condition will be applied to both rules. &lt;br /&gt;&lt;br /&gt;&lt;a name="Cascade"&gt;&lt;/a&gt;
&lt;h2&gt;Setting the Cascade mode&lt;/h2&gt;
You can set the cascade mode to customise how FluentValidation executes chained validators when a particular validator in the chain fails.&lt;br /&gt;&lt;br /&gt;Imagine you have two validators defined as part of a single rule definition, a NotNull validator and a NotEqual validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(x =&amp;gt; x.Surname).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This will first check whether the Surname property is not null and then will check if it&amp;#39;s not equal to the string &amp;quot;foo&amp;quot;. If the first validator (NotNull) fails, then the call to NotEqual will still be invoked. This can be changed by specifying a cascade mode of &lt;b&gt;StopOnFirstFailure&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(x =&amp;gt; x.Surname).Cascade(CascadeMode.StopOnFirstFailure).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, if the NotNull validator fails then the NotEqual validator will not be executed. This is particularly useful if you have a complex chain where each validator depends on the previous validator to succeed. &lt;br /&gt;&lt;br /&gt;The two cascade modes are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Continue (the default) - always invokes all validators in a rule definition&lt;/li&gt;
&lt;li&gt;StopOnFirstFailure - stops executing a rule as soon as a validator fails&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;As well as being set at the rule level, the cascade mode can also be set globally for all validators, or for all the rules in a particular validator class.&lt;br /&gt;&lt;br /&gt;To set the cascade mode globally, you can set the CascadeMode property on the static ValidatorOptions class during your application&amp;#39;s startup routine:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
ValidatorOptions.CascadeMode = CascadeMode.StopOnFirstFailure;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This can then be overriden by individual validator classes or by individual rules.&lt;br /&gt;&lt;br /&gt;To set the cascade mode for all rules inside a single validator class, set the CascadeMode property on AbstractValidator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class PersonValidator : AbstractValidator&amp;lt;Person&amp;gt; {
  public PersonValidator() {
    
    // First set the cascade mode
    CascadeMode = CascadeMode.StopOnFirstFailure;
    
    // Rule definitions follow
    RuleFor(...) 
    RuleFor(...)

   }
}
&lt;/pre&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Mon, 13 May 2013 16:01:25 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Customising 20130513040125P</guid></item><item><title>Updated Wiki: Customising</title><link>https://fluentvalidation.codeplex.com/wikipage?title=Customising&amp;version=12</link><description>&lt;div class="wikidoc"&gt;&lt;a name="CustomError"&gt;&lt;/a&gt;
&lt;h2&gt;Overriding the Default Error&lt;/h2&gt;You can override the default error message for a validator by calling the &lt;b&gt;WithMessage&lt;/b&gt; method on a validator definition:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithMessage(&amp;quot;Please ensure that you have entered your Surname&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that custom error messages can contain placeholders for special values such as the name of the property being validated. This means the above error message could be re-written as:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithMessage(&amp;quot;Please ensure you have entered your {PropertyName}&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...and the value &amp;#39;Surname&amp;#39; will be inserted. For a complete list of error message placeholders see the &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Customising"&gt;Validators&lt;/a&gt; page. &lt;br /&gt;&lt;br /&gt;It is also possible to use your own custom arguments in the validation message. These can either be static values or references to other properties on the object being validated:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
//Using static values in a custom message:
RuleFor(customer =&amp;gt; x.Surname).NotNull().WithMessage(&amp;quot;This message references some static values: {0} {1}&amp;quot;, &amp;quot;hello&amp;quot;, 5);
//Result would be &amp;quot;This message references some static values: hello 5&amp;quot;

//Referencing other property values:
RuleFor(customer =&amp;gt; customer.Surname)
  .NotNull()
  .WithMesasge(&amp;quot;This message references some other properties: Forename: {0} Discount: {1}&amp;quot;, 
    customer =&amp;gt; customer.Forename, 
    customer =&amp;gt; customer.Discount
  );
//Result would be: &amp;quot;This message references some other properties: Forename: Jeremy Discount: 100&amp;quot;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you want to override all of FluentValidation&amp;#39;s default error messages, check out FluentValidation&amp;#39;s support for &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Localization&amp;referringTitle=Customising"&gt;Localization&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a name="PropertyName"&gt;&lt;/a&gt;
&lt;h2&gt;Overriding the Default Property Name&lt;/h2&gt;The default validation error messages contain the property name being validated. For example, if you were to define a validator like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull();
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...then the default error message would be &lt;i&gt;&amp;#39;Surname&amp;#39; must not be empty.&lt;/i&gt; Although you can override the entire error message by calling &lt;b&gt;WithMessage&lt;/b&gt;, you can also replace just the property name by calling &lt;b&gt;WithName&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull().WithName(&amp;quot;Last name&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now the error message would be &lt;i&gt;&amp;#39;Last name&amp;#39; must not be empty.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Note that this only replaces the name of the property in the error message. When you inspect the Errors collection on the ValidationResult, this error will still be associated with a property called &amp;quot;Surname&amp;quot;. If you want to completely rename the property, you can use the &lt;b&gt;WithPropertyName&lt;/b&gt; method instead.&lt;br /&gt;&lt;br /&gt;Property name resolution is also pluggable. By default, the name of the property extracted from the MemberExpression passed to RuleFor. If you want change this logic, you can set the PropertyNameResolver property on the ValidatorOptions class:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
ValidatorOptions.PropertyNameResolver = (type, member) =&amp;gt; {
  if(member != null) {
     return member.Name + &amp;quot;Foo&amp;quot;;
  }
  return null;
};
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is not a realistic example as it changes all properties to have the suffix &amp;quot;Foo&amp;quot;, but hopefully illustrates the point. &lt;br /&gt;&lt;br /&gt;&lt;a name="WhenUnless"&gt;&lt;/a&gt;
&lt;h2&gt;Specifying a condition with When/Unless&lt;/h2&gt;The &lt;b&gt;When&lt;/b&gt; and &lt;b&gt;Unless&lt;/b&gt; methods can be used to specify conditions that control when the rule should execute. For example, this rule on the CustomerDiscount property will only execute when IsPreferredCustomer is true:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.CustomerDiscount).GreaterThan(0).When(customer =&amp;gt; customer.IsPreferredCustomer);
&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Unless&lt;/b&gt; method is simply the opposite of &lt;b&gt;When&lt;/b&gt;. &lt;br /&gt;&lt;br /&gt;If you need to specify the same condition for multiple rules then you can call the top-level When method instead of chaining the When call at the end of the rule:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
When(customer =&amp;gt; customer.IsPreferred, () =&amp;gt; {
   RuleFor(customer =&amp;gt; customer.CustomerDiscount).GreaterThan(0);
   RuleFor(customer =&amp;gt; customer.CreditCardNumber).NotNull();
});
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This time, the condition will be applied to both rules. &lt;br /&gt;&lt;br /&gt;&lt;a name="Cascade"&gt;&lt;/a&gt;
&lt;h2&gt;Setting the Cascade mode&lt;/h2&gt;
You can set the cascade mode to customise how FluentValidation executes chained validators when a particular validator in the chain fails.&lt;br /&gt;&lt;br /&gt;Imagine you have two validators defined as part of a single rule definition, a NotNull validator and a NotEqual validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(x =&amp;gt; x.Surname).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This will first check whether the Surname property is not null and then will check if it&amp;#39;s not equal to the string &amp;quot;foo&amp;quot;. If the first validator (NotNull) fails, then the call to NotEqual will still be invoked. This can be changed by specifying a cascade mode of &lt;b&gt;StopOnFirstFailure&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(x =&amp;gt; x.Surname).Cascade(CascadeMode.StopOnFirstFailure).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, if the NotNull validator fails then the NotEqual validator will not be executed. This is particularly useful if you have a complex chain where each validator depends on the previous validator to succeed. &lt;br /&gt;&lt;br /&gt;The two cascade modes are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Continue (the default) - always invokes all validators in a rule definition&lt;/li&gt;
&lt;li&gt;StopOnFirstFailure - stops executing a rule as soon as a validator fails&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;As well as being set at the rule level, the cascade mode can also be set globally for all validators, or for all the rules in a particular validator class.&lt;br /&gt;&lt;br /&gt;To set the cascade mode globally, you can set the CascadeMode property on the static ValidatorOptions class during your application&amp;#39;s startup routine:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
ValidatorOptions.CascadeMode = CascadeMode.StopOnFirstFailure;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This can then be overriden by individual validator classes or by individual rules.&lt;br /&gt;&lt;br /&gt;To set the cascade mode for all rules inside a single validator class, set the CascadeMode property on AbstractValidator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class PersonValidator : AbstractValidator&amp;lt;Person&amp;gt; {
  public PersonValidator() {
    
    // First set the cascade mode
    CascadeMode = CascadeMode.StopOnFirstFailure;
    
    // Rule definitions follow
    RuleFor(...) 
    RuleFor(...)

   }
}
&lt;/pre&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Mon, 13 May 2013 13:35:29 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Customising 20130513013529P</guid></item><item><title>Updated Wiki: Validators</title><link>https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;version=14</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Built in Validators&lt;/h1&gt;
FluentValidation ships with several built-in validators. The error message for each validator can contain special placeholders that will be filled in when the error message is constructed.&lt;br /&gt;&lt;a name="NotNull"&gt;&lt;/a&gt;
&lt;h2&gt;NotNull Validator&lt;/h2&gt;Description: Ensures that the specified property is not null. &lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull();
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; must not be empty.&lt;br /&gt;String format args:
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="NotEmpty"&gt;&lt;/a&gt;
&lt;h2&gt;NotEmpty Validator&lt;/h2&gt;Description: Ensures that the specified property is not null, an empty string or whitespace (or the default value for value types, eg 0 for int)&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotEmpty();
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; should not be empty.&lt;br /&gt;String format args:
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="NotEqual"&gt;&lt;/a&gt;
&lt;h2&gt;NotEqual Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is not equal to a particular value (or not equal to the value of another property)&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Not equal to a particular value
RuleFor(customer =&amp;gt; customer.Surname).NotEqual(&amp;quot;Foo&amp;quot;);

//Not equal to another property
RuleFor(customer =&amp;gt; customer.Surname).NotEqual(customer =&amp;gt; customer.Forename);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; should not be equal to &amp;#39;Foo&amp;#39;&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} = Value that the property should not equal&lt;/li&gt;&lt;/ul&gt;
&lt;a name="Equal"&gt;&lt;/a&gt;
&lt;h2&gt;Equal Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is equal to a particular value (or equal to the value of another property)&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Equal to a particular value
RuleFor(customer =&amp;gt; customer.Surname).Equal(&amp;quot;Foo&amp;quot;);

//Equal to another property
RuleFor(customer =&amp;gt; customer.Password).Equal(customer =&amp;gt; customer.PasswordConfirmation);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; should be equal to &amp;#39;Foo&amp;#39;&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} = Value that the property should equal&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="Length"&gt;&lt;/a&gt;
&lt;h2&gt;Length Validator&lt;/h2&gt;Description: Ensures that the length of a particular string property is within the specified range.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).Length(1, 250); //must be between 1 and 250 chars (inclusive)
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; must be between 1 and 250 characters. You entered 251 characters.&lt;br /&gt;Note: Only valid on string properties.&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{MinLength} = Minimum length&lt;/li&gt;
&lt;li&gt;{MaxLength} = Maximum length&lt;/li&gt;
&lt;li&gt;{TotalLength} = Number of characters entered&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="LessThan"&gt;&lt;/a&gt;
&lt;h2&gt;Less Than Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is less than a particular value (or less than the value of another property) &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Less than a particular value
RuleFor(customer =&amp;gt; customer.CreditLimit).LessThan(100);

//Less than another property
RuleFor(customer =&amp;gt; customer.CreditLimit).LessThan(customer =&amp;gt; customer.MaxCreditLimit);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Credit Limit&amp;#39; must be less than 100.&lt;br /&gt;Notes: Only valid on types that implement IComparable&amp;lt;T&amp;gt;&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} - The value to which the property was compared&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="LessThanOrEqual"&gt;&lt;/a&gt;
&lt;h2&gt;Less Than Or Equal Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is less than or equal to a particular value (or less than or equal to the value of another property) &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Less than a particular value
RuleFor(customer =&amp;gt; customer.CreditLimit).LessThanOrEqual(100);

//Less than another property
RuleFor(customer =&amp;gt; customer.CreditLimit).LessThanOrEqual(customer =&amp;gt; customer.MaxCreditLimit);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Credit Limit&amp;#39; must be less than or equal to 100.&lt;br /&gt;Notes: Only valid on types that implement IComparable&amp;lt;T&amp;gt;
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} - The value to which the property was compared&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="GreaterThan"&gt;&lt;/a&gt;
&lt;h2&gt;Greater Than Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is greater than a particular value (or greater than the value of another property) &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Greater than a particular value
RuleFor(customer =&amp;gt; customer.CreditLimit).GreaterThan(0);

//Greater than another property
RuleFor(customer =&amp;gt; customer.CreditLimit).GreaterThan(customer =&amp;gt; customer.MinimumCreditLimit);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Credit Limit&amp;#39; must be greater than 0.&lt;br /&gt;Notes: Only valid on types that implement IComparable&amp;lt;T&amp;gt;
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} - The value to which the property was compared&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="GreaterThanOrEqual"&gt;&lt;/a&gt;
&lt;h2&gt;Greater Than Or Equal Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is greater than or equal to a particular value (or greater than or equal to the value of another property) &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Greater than a particular value
RuleFor(customer =&amp;gt; customer.CreditLimit).GreaterThanOrEqual(1);

//Greater than another property
RuleFor(customer =&amp;gt; customer.CreditLimit).GreaterThanOrEqual(customer =&amp;gt; customer.MinimumCreditLimit);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Credit Limit&amp;#39; must be greater than or equal to 1.&lt;br /&gt;Notes: Only valid on types that implement IComparable&amp;lt;T&amp;gt;
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} - The value to which the property was compared&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="Predicate"&gt;&lt;/a&gt;
&lt;h2&gt;Predicate Validator (aka Must)&lt;/h2&gt;Description: Passes the value of the specified property into a custom delegate that can perform custom validation logic on the value&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).Must(surname =&amp;gt; &amp;quot;Foo&amp;quot;.Equals(surname));
&lt;/pre&gt;&lt;br /&gt;Example error: The specified condition was not met for &amp;#39;Surname&amp;#39; &lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Note that there is an additional overload for Must that also accepts an instance of the parent object being validated. This can be useful if you want to compare the current property with another property from inside the predicate:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).Must((customer, surname) =&amp;gt; surname != customer.Forename)
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;(Note that in this particular example, it would be better to use the cross-property version of NotEqual)&lt;br /&gt;&lt;br /&gt;&lt;a name="Regex"&gt;&lt;/a&gt;
&lt;h2&gt;Regular Expression Validator&lt;/h2&gt;Description: Ensures that the value of the specified property matches the given regular expression. &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).Matches(&amp;quot;some regex here&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; is not in the correct format.&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="Email"&gt;&lt;/a&gt;
&lt;h2&gt;Email Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is a valid email address format. &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Email).EmailAddress();
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Email&amp;#39; is not a valid email address.&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
The regular expression used by the email validator can be found at &lt;a href="http://regexlib.com/REDetails.aspx?regexp_id=1448"&gt;http://regexlib.com/REDetails.aspx?regexp_id=1448&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Tue, 07 May 2013 10:29:27 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Validators 20130507102927A</guid></item><item><title>Updated Wiki: Validators</title><link>https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;version=13</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Built in Validators&lt;/h1&gt;
FluentValidation ships with several built-in validators. The error message for each validator can contain special placeholders that will be filled in when the error message is constructed.&lt;br /&gt;&lt;a name="NotNull"&gt;&lt;/a&gt;
&lt;h2&gt;NotNull Validator&lt;/h2&gt;Description: Ensures that the specified property is not null. &lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotNull();
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; must not be empty.&lt;br /&gt;String format args:
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="NotEmpty"&gt;&lt;/a&gt;
&lt;h2&gt;NotEmpty Validator&lt;/h2&gt;Description: Ensures that the specified property is not null, an empty string or whitespace (or the default value for value types, eg 0 for int)&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).NotEmpty();
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; should not be empty.&lt;br /&gt;String format args:
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="NotEqual"&gt;&lt;/a&gt;
&lt;h2&gt;NotEqual Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is not equal to a particular value (or not equal to the value of another property)&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Not equal to a particular value
RuleFor(customer =&amp;gt; customer.Surname).NotEqual(&amp;quot;Foo&amp;quot;);

//Not equal to another property
RuleFor(customer =&amp;gt; customer.Surname).NotEqual(customer =&amp;gt; customer.Forename);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; should not be equal to &amp;#39;Foo&amp;#39;&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} = Value that the property should not equal&lt;/li&gt;&lt;/ul&gt;
&lt;a name="Equal"&gt;&lt;/a&gt;
&lt;h2&gt;Equal Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is equal to a particular value (or equal to the value of another property)&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Equal to a particular value
RuleFor(customer =&amp;gt; customer.Surname).Equal(&amp;quot;Foo&amp;quot;);

//Equal to another property
RuleFor(customer =&amp;gt; customer.Password).Equal(customer =&amp;gt; customer.PasswordConfirmation);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; should be equal to &amp;#39;Foo&amp;#39;&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} = Value that the property should equal&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="Length"&gt;&lt;/a&gt;
&lt;h2&gt;Length Validator&lt;/h2&gt;Description: Ensures that the length of a particular string property is within the specified range.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).Length(1, 250); //must be between 1 and 250 chars (inclusive)
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; must be between 1 and 250 characters. You entered 251 characters.&lt;br /&gt;Note: Only valid on string properties.&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{MinLength} = Minimum length&lt;/li&gt;
&lt;li&gt;{MaxLength} = Maximum length&lt;/li&gt;
&lt;li&gt;{TotalLength} = Number of characters entered&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="LessThan"&gt;&lt;/a&gt;
&lt;h2&gt;Less Than Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is less than a particular value (or less than the value of another property) &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Less than a particular value
RuleFor(customer =&amp;gt; customer.CreditLimit).LessThan(100);

//Less than another property
RuleFor(customer =&amp;gt; customer.CreditLimit).LessThan(customer =&amp;gt; customer.MaxCreditLimit);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Credit Limit&amp;#39; must be less than 100.&lt;br /&gt;Notes: Only valid on types that implement IComparable&amp;lt;T&amp;gt;&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} - The value to which the property was compared&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="LessThanOrEqual"&gt;&lt;/a&gt;
&lt;h2&gt;Less Than Or Equal Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is less than or equal to a particular value (or less than or equal to the value of another property) &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Less than a particular value
RuleFor(customer =&amp;gt; customer.CreditLimit).LessThanOrEqual(100);

//Less than another property
RuleFor(customer =&amp;gt; customer.CreditLimit).LessThanOrEqual(customer =&amp;gt; customer.MaxCreditLimit);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Credit Limit&amp;#39; must be less than or equal to 100.&lt;br /&gt;Notes: Only valid on types that implement IComparable&amp;lt;T&amp;gt;
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} - The value to which the property was compared&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="GreaterThan"&gt;&lt;/a&gt;
&lt;h2&gt;Greater Than Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is greater than a particular value (or greater than the value of another property) &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Less than a particular value
RuleFor(customer =&amp;gt; customer.CreditLimit).GreaterThan(0);

//Less than another property
RuleFor(customer =&amp;gt; customer.CreditLimit).GreaterThan(customer =&amp;gt; customer.MinimumCreditLimit);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Credit Limit&amp;#39; must be greater than 0.&lt;br /&gt;Notes: Only valid on types that implement IComparable&amp;lt;T&amp;gt;
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} - The value to which the property was compared&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="GreaterThanOrEqual"&gt;&lt;/a&gt;
&lt;h2&gt;Greater Than Or Equal Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is greater than or equal to a particular value (or greater than or equal to the value of another property) &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
//Less than a particular value
RuleFor(customer =&amp;gt; customer.CreditLimit).GreaterThanOrEqual(1);

//Less than another property
RuleFor(customer =&amp;gt; customer.CreditLimit).GreaterThanOrEqual(customer =&amp;gt; customer.MinimumCreditLimit);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Credit Limit&amp;#39; must be greater than or equal to 1.&lt;br /&gt;Notes: Only valid on types that implement IComparable&amp;lt;T&amp;gt;
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{ComparisonValue} - The value to which the property was compared&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="Predicate"&gt;&lt;/a&gt;
&lt;h2&gt;Predicate Validator (aka Must)&lt;/h2&gt;Description: Passes the value of the specified property into a custom delegate that can perform custom validation logic on the value&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).Must(surname =&amp;gt; &amp;quot;Foo&amp;quot;.Equals(surname));
&lt;/pre&gt;&lt;br /&gt;Example error: The specified condition was not met for &amp;#39;Surname&amp;#39; &lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;Note that there is an additional overload for Must that also accepts an instance of the parent object being validated. This can be useful if you want to compare the current property with another property from inside the predicate:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).Must((customer, surname) =&amp;gt; surname != customer.Forename)
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;(Note that in this particular example, it would be better to use the cross-property version of NotEqual)&lt;br /&gt;&lt;br /&gt;&lt;a name="Regex"&gt;&lt;/a&gt;
&lt;h2&gt;Regular Expression Validator&lt;/h2&gt;Description: Ensures that the value of the specified property matches the given regular expression. &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Surname).Matches(&amp;quot;some regex here&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Surname&amp;#39; is not in the correct format.&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
&lt;a name="Email"&gt;&lt;/a&gt;
&lt;h2&gt;Email Validator&lt;/h2&gt;Description: Ensures that the value of the specified property is a valid email address format. &lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;
RuleFor(customer =&amp;gt; customer.Email).EmailAddress();
&lt;/pre&gt;&lt;br /&gt;Example error: &amp;#39;Email&amp;#39; is not a valid email address.&lt;br /&gt;String format args: 
&lt;ul&gt;&lt;li&gt;{PropertyName} = The name of the property being validated&lt;/li&gt;
&lt;li&gt;{PropertyValue} = The current value of the property&lt;/li&gt;&lt;/ul&gt;
The regular expression used by the email validator can be found at &lt;a href="http://regexlib.com/REDetails.aspx?regexp_id=1448"&gt;http://regexlib.com/REDetails.aspx?regexp_id=1448&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Tue, 07 May 2013 10:28:47 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Validators 20130507102847A</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentvalidation.codeplex.com/documentation?version=16</link><description>&lt;div class="wikidoc"&gt;This documentation is for the 4.0 release of FluentValidation.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;referringTitle=Documentation"&gt;Creating a Validator Class&lt;/a&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;referringTitle=Documentation&amp;ANCHOR#Chaining"&gt;Chaining Validators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;referringTitle=Documentation&amp;ANCHOR#ValidationResult"&gt;Validation Results&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;referringTitle=Documentation&amp;ANCHOR#ValidateAndThrow"&gt;Throwing Exceptions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;referringTitle=Documentation&amp;ANCHOR#ReusingValidators"&gt;Re-using Validators on Complex Properties&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;referringTitle=Documentation&amp;ANCHOR#Collections"&gt;Re-using Validators on Nested Collections&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;referringTitle=Documentation&amp;ANCHOR#RuleSets"&gt;Rule Sets&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation"&gt;Built in Validators&lt;/a&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#NotNull"&gt;NotNull Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#NotEmpty"&gt;NotEmpty Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#NotEqual"&gt;NotEqual Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#Equal"&gt;Equal Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#Length"&gt;Length Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#LessThan"&gt;Less Than Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#LessThanOrEqual"&gt;Less Than Or Equal Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#GreaterThan"&gt;Greater Than Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#GreaterThanOrEqual"&gt;GreaterThan Or Equal Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#Predicate"&gt;Predicate Validator &amp;#40;aka Must&amp;#41;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#Regex"&gt;RegEx Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Validators&amp;referringTitle=Documentation&amp;ANCHOR#Email"&gt;Email Validator&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Customising&amp;referringTitle=Documentation"&gt;Configuring&amp;#47;Customising a validator&lt;/a&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Customising&amp;referringTitle=Documentation&amp;ANCHOR#CustomError"&gt;Overriding the default error message&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Customising&amp;referringTitle=Documentation&amp;ANCHOR#PropertyName"&gt;Overriding the default property name&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Customising&amp;referringTitle=Documentation&amp;ANCHOR#WhenUnless"&gt;Specifying a condition with When&amp;#47;Unless&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Customising&amp;referringTitle=Documentation&amp;ANCHOR#Cascade"&gt;Specifying the cascade mode&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Custom&amp;referringTitle=Documentation"&gt;Custom Validators&lt;/a&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Custom&amp;referringTitle=Documentation&amp;ANCHOR#CustomValidator"&gt;Writing a custom Property Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Custom&amp;referringTitle=Documentation&amp;ANCHOR#AbstractValidatorCustom"&gt;Using AbstractValidator.Custom&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Localization&amp;referringTitle=Documentation"&gt;Localization&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=Testing&amp;referringTitle=Documentation"&gt;Testing Validators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=mvc&amp;referringTitle=Documentation"&gt;Integrating with ASP.NET MVC&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=ValidatorFactory&amp;referringTitle=Documentation"&gt;Using a Validator Factory with an IoC container&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Tue, 07 May 2013 10:16:04 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20130507101604A</guid></item><item><title>Updated Wiki: mvc</title><link>https://fluentvalidation.codeplex.com/wikipage?title=mvc&amp;version=8</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Integration with ASP.NET MVC&lt;/h1&gt;
FluentValidation can be integrated with ASP.NET MVC 3 and ASP.NET MVC 4. Once enabled, MVC will use FluentValidation to validate objects that are passed in to controller actions by the model binding infrastructure. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; There is no built-in integration for ASP.NET Web API.&lt;br /&gt;&lt;br /&gt;To enable MVC integration, you&amp;#39;ll need to add a reference to the &lt;b&gt;FluentValidation.Mvc3&lt;/b&gt; or &lt;b&gt;FluentValidation.Mvc4&lt;/b&gt; assemblies (either available through the download package on this site, or by installing the FluentValidation.Mvc3 / FluentValidation.Mvc4 NuGet packages). &lt;br /&gt;&lt;br /&gt;Once installed, you&amp;#39;ll need to configure the &lt;b&gt;FluentValidationModelValidatorProvider&lt;/b&gt; (which lives in the FluentValidation.Mvc namespace) during the Application_Start event of your MVC application. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
protected void Application_Start() {
    AreaRegistration.RegisterAllAreas();

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    FluentValidationModelValidatorProvider.Configure();
}

&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Internally, FluentValidation&amp;#39;s MVC integration makes use of a &lt;i&gt;validator factory&lt;/i&gt; to know how to work out which validator should be used to validate a particular type. By default, FluentValidation ships with an AttributedValidatorFactory that allows you to link a validator to the type that it validates by decorating the class to validate with an attribute that identifies its corresponding validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
[Validator(typeof(PersonValidator))]
public class Person {
	public int Id { get; set; }
	public string Name { get; set; }
	public string Email { get; set; }
	public int Age { get; set; }
}
 
public class PersonValidator : AbstractValidator&amp;lt;Person&amp;gt; {
	public PersonValidator() {
		RuleFor(x =&amp;gt; x.Id).NotNull();
		RuleFor(x =&amp;gt; x.Name).Length(0, 10);
		RuleFor(x =&amp;gt; x.Email).EmailAddress();
		RuleFor(x =&amp;gt; x.Age).InclusiveBetween(18, 60);
	}
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Instead of using an attribute, you can also use &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=ValidatorFactory&amp;referringTitle=mvc"&gt;a custom validator factory with an IoC container&lt;/a&gt;. You can tell the FluentValidationModelValidatorProvider to use a different validator factory by passing a nested closure into the Configure method which allows the provider to be customized:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
FluentValidationModelValidatorProvider.Configure(provider =&amp;gt; {
  provider.ValidatorFactory = new MyCustomValidatorFactory();
});
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Finally, we can create the controller and associated view:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class PeopleController : Controller {
	public ActionResult Create() {
		return View();
	}
 
	[HttpPost]
	public ActionResult Create(Person person) {
 
		if(! ModelState.IsValid) { // re-render the view when validation failed.
			return View(&amp;quot;Create&amp;quot;, person);
		}
 
		TempData[&amp;quot;notice&amp;quot;] = &amp;quot;Person successfully created&amp;quot;;
		return RedirectToAction(&amp;quot;Index&amp;quot;);
 
	}
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...and here&amp;#39;s the corresponding view (using Razor):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
@Html.ValidationSummary()
 
@using (Html.BeginForm()) {
	Id: @Html.TextBoxFor(x =&amp;gt; x.Id) @Html.ValidationMessageFor(x =&amp;gt; x.Id)
	&amp;lt;br /&amp;gt;
	Name: @Html.TextBoxFor(x =&amp;gt; x.Name) @Html.ValidationMessageFor(x =&amp;gt; x.Name) 		
	&amp;lt;br /&amp;gt;
	Email: @Html.TextBoxFor(x =&amp;gt; x.Email) @Html.ValidationMessageFor(x =&amp;gt; x.Email)
	&amp;lt;br /&amp;gt;
	Age: @Html.TextBoxFor(x =&amp;gt; x.Age) @Html.ValidationMessageFor(x =&amp;gt; x.Age)
 
	&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;
 
	&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;submit&amp;quot; /&amp;gt;
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now when you post the form MVC’s DefaultModelBinder will validate the Person object using the FluentValidationModelValidatorProvider.&lt;br /&gt;&lt;br /&gt;Note that FluentValidation will also work with ASP.NET MVC&amp;#39;s client-side validation, but not all rules are supported. For example, any rules defined using a condition (with When/Unless), custom validators, or calls to Must will not run on the client side. The following validators are supported on the client:&lt;br /&gt;&lt;br /&gt;*NotNull/NotEmpty&lt;br /&gt;*Matches (regex)&lt;br /&gt;*InclusiveBetween (range)&lt;br /&gt;*CreditCard&lt;br /&gt;*Email&lt;br /&gt;*EqualTo (cross-property equality comparison)&lt;br /&gt;*Length&lt;br /&gt;
&lt;h2&gt;Validator customization&lt;/h2&gt;
The downside of using this automatic integration is that you don’t have access to the validator directly which means that you don’t have as much control over the validation processes compared to running the validator manually.&lt;br /&gt;&lt;br /&gt;With FluentValidation v3 you can use the CustomizeValidatorAttribute to configure how the validator will be run. For example, if you want the validator to only run for a particular ruleset then you can specify that ruleset name by attributing the parameter that is going to be validated:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public ActionResult Save([CustomizeValidator(RuleSet=&amp;quot;MyRuleset&amp;quot;)] Customer cust) {
  // ...
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is the equivalent of specifying the ruleset if you were to pass a ruleset name to a validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
var validator = new CustomerValidator();
var customer = new Customer();
var result = validator.Validate(customer, ruleSet: &amp;quot;MyRuleset&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The attribute can also be used to invoke validation for individual properties:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public ActionResult Save([CustomizeValidator(Properties=&amp;quot;Surname,Forename&amp;quot;)] Customer cust) {
  // ...
}
&lt;/pre&gt;&lt;br /&gt;…which would be the equivalent of specifying properties in the call to validator.Validate:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
var validator = new CustomerValidator();
var customer = new Customer();
var result = validator.Validate(customer, properties: new[] { &amp;quot;Surname&amp;quot;, &amp;quot;Forename&amp;quot; });
&lt;/pre&gt;&lt;br /&gt;
&lt;h2&gt;Validator Interceptors&lt;/h2&gt;
You can further customize this process by using an interceptor. An interceptor has to implement the IValidatorInterceptor interface from the FluentValidation.Mvc namespace:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public interface IValidatorInterceptor {
    ValidationContext BeforeMvcValidation(ControllerContext controllerContext, ValidationContext validationContext);
 
    ValidationResult AfterMvcValidation(ControllerContext controllerContext, ValidationContext validationContext, ValidationResult result);
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This interface has two methods – BeforeMvcValidation and AfterMvcValidation. If you implement this interface in your validator classes then these methods will be called as appropriate during the MVC validation pipeline.&lt;br /&gt;&lt;br /&gt;BeforeMvcValidation is invoked after the appropriate validator has been selected but before it is invoked. One of the arguments passed to this method is a ValidationContext that will eventually be passed to the validator. The context has several properties including a reference to the object being validated. If we want to change which rules are going to be invoked (for example, by using a custom ValidatorSelector) then we can create a new ValidationContext, set its Selector property, and return that from the BeforeMvcValidation method.&lt;br /&gt;&lt;br /&gt;Likewise, AfterMvcValidation occurs after validation has occurs. This time, we also have a reference to the result of the validation. Here we can do some additional processing on the error messages before they’re added to modelstate.&lt;br /&gt;&lt;br /&gt;As well as implementing this interface directly in a validator class, we can also implement it externally, and specify the interceptor by using a CustomizeValidatorAttribute on an action method parameter:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public ActionResult Save([CustomizeValidator(Interceptor=typeof(MyCustomerInterceptor))] Customer cust) {
 //...
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In this case, the interceptor has to be a class that implements IValidatorInterceptor and has a public, parameterless constructor. The advantage of this approach is that your validators don’t have to be in an assembly that directly references System.Web.Mvc.&lt;br /&gt;&lt;br /&gt;Note that this is considered to be an advanced scenario. Most of the time you probably won’t need to use an interceptor, but the option is there if you want it.&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Thu, 02 May 2013 11:27:33 GMT</pubDate><guid isPermaLink="false">Updated Wiki: mvc 20130502112733A</guid></item><item><title>Updated Wiki: mvc</title><link>https://fluentvalidation.codeplex.com/wikipage?title=mvc&amp;version=7</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Integration with ASP.NET MVC&lt;/h1&gt;
FluentValidation can be integrated with ASP.NET MVC 3 and ASP.NET MVC 4. Once enabled, MVC will use FluentValidation to validate objects that are passed in to controller actions by the model binding infrastructure. &lt;br /&gt;&lt;br /&gt;To enable MVC integration, you&amp;#39;ll need to add a reference to the &lt;b&gt;FluentValidation.Mvc3&lt;/b&gt; or &lt;b&gt;FluentValidation.Mvc4&lt;/b&gt; assemblies (either available through the download package on this site, or by installing the FluentValidation.Mvc3 / FluentValidation.Mvc4 NuGet packages). &lt;br /&gt;&lt;br /&gt;Once installed, you&amp;#39;ll need to configure the &lt;b&gt;FluentValidationModelValidatorProvider&lt;/b&gt; (which lives in the FluentValidation.Mvc namespace) during the Application_Start event of your MVC application. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
protected void Application_Start() {
    AreaRegistration.RegisterAllAreas();

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    FluentValidationModelValidatorProvider.Configure();
}

&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Internally, FluentValidation&amp;#39;s MVC integration makes use of a &lt;i&gt;validator factory&lt;/i&gt; to know how to work out which validator should be used to validate a particular type. By default, FluentValidation ships with an AttributedValidatorFactory that allows you to link a validator to the type that it validates by decorating the class to validate with an attribute that identifies its corresponding validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
[Validator(typeof(PersonValidator))]
public class Person {
	public int Id { get; set; }
	public string Name { get; set; }
	public string Email { get; set; }
	public int Age { get; set; }
}
 
public class PersonValidator : AbstractValidator&amp;lt;Person&amp;gt; {
	public PersonValidator() {
		RuleFor(x =&amp;gt; x.Id).NotNull();
		RuleFor(x =&amp;gt; x.Name).Length(0, 10);
		RuleFor(x =&amp;gt; x.Email).EmailAddress();
		RuleFor(x =&amp;gt; x.Age).InclusiveBetween(18, 60);
	}
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Instead of using an attribute, you can also use &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=ValidatorFactory&amp;referringTitle=mvc"&gt;a custom validator factory with an IoC container&lt;/a&gt;. You can tell the FluentValidationModelValidatorProvider to use a different validator factory by passing a nested closure into the Configure method which allows the provider to be customized:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
FluentValidationModelValidatorProvider.Configure(provider =&amp;gt; {
  provider.ValidatorFactory = new MyCustomValidatorFactory();
});
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Finally, we can create the controller and associated view:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class PeopleController : Controller {
	public ActionResult Create() {
		return View();
	}
 
	[HttpPost]
	public ActionResult Create(Person person) {
 
		if(! ModelState.IsValid) { // re-render the view when validation failed.
			return View(&amp;quot;Create&amp;quot;, person);
		}
 
		TempData[&amp;quot;notice&amp;quot;] = &amp;quot;Person successfully created&amp;quot;;
		return RedirectToAction(&amp;quot;Index&amp;quot;);
 
	}
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...and here&amp;#39;s the corresponding view (using Razor):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
@Html.ValidationSummary()
 
@using (Html.BeginForm()) {
	Id: @Html.TextBoxFor(x =&amp;gt; x.Id) @Html.ValidationMessageFor(x =&amp;gt; x.Id)
	&amp;lt;br /&amp;gt;
	Name: @Html.TextBoxFor(x =&amp;gt; x.Name) @Html.ValidationMessageFor(x =&amp;gt; x.Name) 		
	&amp;lt;br /&amp;gt;
	Email: @Html.TextBoxFor(x =&amp;gt; x.Email) @Html.ValidationMessageFor(x =&amp;gt; x.Email)
	&amp;lt;br /&amp;gt;
	Age: @Html.TextBoxFor(x =&amp;gt; x.Age) @Html.ValidationMessageFor(x =&amp;gt; x.Age)
 
	&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;
 
	&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;submit&amp;quot; /&amp;gt;
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now when you post the form MVC’s DefaultModelBinder will validate the Person object using the FluentValidationModelValidatorProvider.&lt;br /&gt;&lt;br /&gt;Note that FluentValidation will also work with ASP.NET MVC&amp;#39;s client-side validation, but not all rules are supported. For example, any rules defined using a condition (with When/Unless), custom validators, or calls to Must will not run on the client side. The following validators are supported on the client:&lt;br /&gt;&lt;br /&gt;*NotNull/NotEmpty&lt;br /&gt;*Matches (regex)&lt;br /&gt;*InclusiveBetween (range)&lt;br /&gt;*CreditCard&lt;br /&gt;*Email&lt;br /&gt;*EqualTo (cross-property equality comparison)&lt;br /&gt;*Length&lt;br /&gt;
&lt;h2&gt;Validator customization&lt;/h2&gt;
The downside of using this automatic integration is that you don’t have access to the validator directly which means that you don’t have as much control over the validation processes compared to running the validator manually.&lt;br /&gt;&lt;br /&gt;With FluentValidation v3 you can use the CustomizeValidatorAttribute to configure how the validator will be run. For example, if you want the validator to only run for a particular ruleset then you can specify that ruleset name by attributing the parameter that is going to be validated:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public ActionResult Save([CustomizeValidator(RuleSet=&amp;quot;MyRuleset&amp;quot;)] Customer cust) {
  // ...
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is the equivalent of specifying the ruleset if you were to pass a ruleset name to a validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
var validator = new CustomerValidator();
var customer = new Customer();
var result = validator.Validate(customer, ruleSet: &amp;quot;MyRuleset&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The attribute can also be used to invoke validation for individual properties:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public ActionResult Save([CustomizeValidator(Properties=&amp;quot;Surname,Forename&amp;quot;)] Customer cust) {
  // ...
}
&lt;/pre&gt;&lt;br /&gt;…which would be the equivalent of specifying properties in the call to validator.Validate:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
var validator = new CustomerValidator();
var customer = new Customer();
var result = validator.Validate(customer, properties: new[] { &amp;quot;Surname&amp;quot;, &amp;quot;Forename&amp;quot; });
&lt;/pre&gt;&lt;br /&gt;
&lt;h2&gt;Validator Interceptors&lt;/h2&gt;
You can further customize this process by using an interceptor. An interceptor has to implement the IValidatorInterceptor interface from the FluentValidation.Mvc namespace:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public interface IValidatorInterceptor {
    ValidationContext BeforeMvcValidation(ControllerContext controllerContext, ValidationContext validationContext);
 
    ValidationResult AfterMvcValidation(ControllerContext controllerContext, ValidationContext validationContext, ValidationResult result);
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This interface has two methods – BeforeMvcValidation and AfterMvcValidation. If you implement this interface in your validator classes then these methods will be called as appropriate during the MVC validation pipeline.&lt;br /&gt;&lt;br /&gt;BeforeMvcValidation is invoked after the appropriate validator has been selected but before it is invoked. One of the arguments passed to this method is a ValidationContext that will eventually be passed to the validator. The context has several properties including a reference to the object being validated. If we want to change which rules are going to be invoked (for example, by using a custom ValidatorSelector) then we can create a new ValidationContext, set its Selector property, and return that from the BeforeMvcValidation method.&lt;br /&gt;&lt;br /&gt;Likewise, AfterMvcValidation occurs after validation has occurs. This time, we also have a reference to the result of the validation. Here we can do some additional processing on the error messages before they’re added to modelstate.&lt;br /&gt;&lt;br /&gt;As well as implementing this interface directly in a validator class, we can also implement it externally, and specify the interceptor by using a CustomizeValidatorAttribute on an action method parameter:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public ActionResult Save([CustomizeValidator(Interceptor=typeof(MyCustomerInterceptor))] Customer cust) {
 //...
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In this case, the interceptor has to be a class that implements IValidatorInterceptor and has a public, parameterless constructor. The advantage of this approach is that your validators don’t have to be in an assembly that directly references System.Web.Mvc.&lt;br /&gt;&lt;br /&gt;Note that this is considered to be an advanced scenario. Most of the time you probably won’t need to use an interceptor, but the option is there if you want it.&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Thu, 02 May 2013 08:37:29 GMT</pubDate><guid isPermaLink="false">Updated Wiki: mvc 20130502083729A</guid></item><item><title>Updated Wiki: mvc</title><link>https://fluentvalidation.codeplex.com/wikipage?title=mvc&amp;version=6</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Integration with ASP.NET MVC&lt;/h1&gt;
FluentValidation can be integrated with ASP.NET MVC 3 and ASP.NET MVC 4. Once enabled, MVC will use FluentValidation to validate objects that are passed in to controller actions by the model binding infrastructure. &lt;br /&gt;&lt;br /&gt;To enable MVC integration, you&amp;#39;ll need to add a reference to the &lt;b&gt;FluentValidation.Mvc3&lt;/b&gt; assembly (either available through the download package on this site, or by installing the FluentValidation.Mvc3 NuGet package). &lt;br /&gt;&lt;br /&gt;Once installed, you&amp;#39;ll need to configure the &lt;b&gt;FluentValidationModelValidatorProvider&lt;/b&gt; (which lives in the FluentValidation.Mvc namespace) during the Application_Start event of your MVC application. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
protected void Application_Start() {
    AreaRegistration.RegisterAllAreas();

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    FluentValidationModelValidatorProvider.Configure();
}

&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Internally, FluentValidation&amp;#39;s MVC integration makes use of a &lt;i&gt;validator factory&lt;/i&gt; to know how to work out which validator should be used to validate a particular type. By default, FluentValidation ships with an AttributedValidatorFactory that allows you to link a validator to the type that it validates by decorating the class to validate with an attribute that identifies its corresponding validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
[Validator(typeof(PersonValidator))]
public class Person {
	public int Id { get; set; }
	public string Name { get; set; }
	public string Email { get; set; }
	public int Age { get; set; }
}
 
public class PersonValidator : AbstractValidator&amp;lt;Person&amp;gt; {
	public PersonValidator() {
		RuleFor(x =&amp;gt; x.Id).NotNull();
		RuleFor(x =&amp;gt; x.Name).Length(0, 10);
		RuleFor(x =&amp;gt; x.Email).EmailAddress();
		RuleFor(x =&amp;gt; x.Age).InclusiveBetween(18, 60);
	}
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Instead of using an attribute, you can also use &lt;a href="https://fluentvalidation.codeplex.com/wikipage?title=ValidatorFactory&amp;referringTitle=mvc"&gt;a custom validator factory with an IoC container&lt;/a&gt;. You can tell the FluentValidationModelValidatorProvider to use a different validator factory by passing a nested closure into the Configure method which allows the provider to be customized:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
FluentValidationModelValidatorProvider.Configure(provider =&amp;gt; {
  provider.ValidatorFactory = new MyCustomValidatorFactory();
});
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Finally, we can create the controller and associated view:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class PeopleController : Controller {
	public ActionResult Create() {
		return View();
	}
 
	[HttpPost]
	public ActionResult Create(Person person) {
 
		if(! ModelState.IsValid) { // re-render the view when validation failed.
			return View(&amp;quot;Create&amp;quot;, person);
		}
 
		TempData[&amp;quot;notice&amp;quot;] = &amp;quot;Person successfully created&amp;quot;;
		return RedirectToAction(&amp;quot;Index&amp;quot;);
 
	}
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...and here&amp;#39;s the corresponding view (using Razor):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
@Html.ValidationSummary()
 
@using (Html.BeginForm()) {
	Id: @Html.TextBoxFor(x =&amp;gt; x.Id) @Html.ValidationMessageFor(x =&amp;gt; x.Id)
	&amp;lt;br /&amp;gt;
	Name: @Html.TextBoxFor(x =&amp;gt; x.Name) @Html.ValidationMessageFor(x =&amp;gt; x.Name) 		
	&amp;lt;br /&amp;gt;
	Email: @Html.TextBoxFor(x =&amp;gt; x.Email) @Html.ValidationMessageFor(x =&amp;gt; x.Email)
	&amp;lt;br /&amp;gt;
	Age: @Html.TextBoxFor(x =&amp;gt; x.Age) @Html.ValidationMessageFor(x =&amp;gt; x.Age)
 
	&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;
 
	&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;submit&amp;quot; /&amp;gt;
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now when you post the form MVC’s DefaultModelBinder will validate the Person object using the FluentValidationModelValidatorProvider.&lt;br /&gt;&lt;br /&gt;Note that FluentValidation will also work with ASP.NET MVC&amp;#39;s client-side validation, but not all rules are supported. For example, any rules defined using a condition (with When/Unless), custom validators, or calls to Must will not run on the client side. The following validators are supported on the client:&lt;br /&gt;&lt;br /&gt;*NotNull/NotEmpty&lt;br /&gt;*Matches (regex)&lt;br /&gt;*InclusiveBetween (range)&lt;br /&gt;*CreditCard&lt;br /&gt;*Email&lt;br /&gt;*EqualTo (cross-property equality comparison)&lt;br /&gt;*Length&lt;br /&gt;
&lt;h2&gt;Validator customization&lt;/h2&gt;
The downside of using this automatic integration is that you don’t have access to the validator directly which means that you don’t have as much control over the validation processes compared to running the validator manually.&lt;br /&gt;&lt;br /&gt;With FluentValidation v3 you can use the CustomizeValidatorAttribute to configure how the validator will be run. For example, if you want the validator to only run for a particular ruleset then you can specify that ruleset name by attributing the parameter that is going to be validated:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public ActionResult Save([CustomizeValidator(RuleSet=&amp;quot;MyRuleset&amp;quot;)] Customer cust) {
  // ...
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is the equivalent of specifying the ruleset if you were to pass a ruleset name to a validator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
var validator = new CustomerValidator();
var customer = new Customer();
var result = validator.Validate(customer, ruleSet: &amp;quot;MyRuleset&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The attribute can also be used to invoke validation for individual properties:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public ActionResult Save([CustomizeValidator(Properties=&amp;quot;Surname,Forename&amp;quot;)] Customer cust) {
  // ...
}
&lt;/pre&gt;&lt;br /&gt;…which would be the equivalent of specifying properties in the call to validator.Validate:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
var validator = new CustomerValidator();
var customer = new Customer();
var result = validator.Validate(customer, properties: new[] { &amp;quot;Surname&amp;quot;, &amp;quot;Forename&amp;quot; });
&lt;/pre&gt;&lt;br /&gt;
&lt;h2&gt;Validator Interceptors&lt;/h2&gt;
You can further customize this process by using an interceptor. An interceptor has to implement the IValidatorInterceptor interface from the FluentValidation.Mvc namespace:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public interface IValidatorInterceptor {
    ValidationContext BeforeMvcValidation(ControllerContext controllerContext, ValidationContext validationContext);
 
    ValidationResult AfterMvcValidation(ControllerContext controllerContext, ValidationContext validationContext, ValidationResult result);
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This interface has two methods – BeforeMvcValidation and AfterMvcValidation. If you implement this interface in your validator classes then these methods will be called as appropriate during the MVC validation pipeline.&lt;br /&gt;&lt;br /&gt;BeforeMvcValidation is invoked after the appropriate validator has been selected but before it is invoked. One of the arguments passed to this method is a ValidationContext that will eventually be passed to the validator. The context has several properties including a reference to the object being validated. If we want to change which rules are going to be invoked (for example, by using a custom ValidatorSelector) then we can create a new ValidationContext, set its Selector property, and return that from the BeforeMvcValidation method.&lt;br /&gt;&lt;br /&gt;Likewise, AfterMvcValidation occurs after validation has occurs. This time, we also have a reference to the result of the validation. Here we can do some additional processing on the error messages before they’re added to modelstate.&lt;br /&gt;&lt;br /&gt;As well as implementing this interface directly in a validator class, we can also implement it externally, and specify the interceptor by using a CustomizeValidatorAttribute on an action method parameter:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public ActionResult Save([CustomizeValidator(Interceptor=typeof(MyCustomerInterceptor))] Customer cust) {
 //...
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In this case, the interceptor has to be a class that implements IValidatorInterceptor and has a public, parameterless constructor. The advantage of this approach is that your validators don’t have to be in an assembly that directly references System.Web.Mvc.&lt;br /&gt;&lt;br /&gt;Note that this is considered to be an advanced scenario. Most of the time you probably won’t need to use an interceptor, but the option is there if you want it.&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Thu, 02 May 2013 08:36:58 GMT</pubDate><guid isPermaLink="false">Updated Wiki: mvc 20130502083658A</guid></item><item><title>Updated Wiki: Home</title><link>https://fluentvalidation.codeplex.com/wikipage?version=36</link><description>&lt;div class="wikidoc"&gt;&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt;A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules for your business objects. &lt;br /&gt;&lt;br /&gt;If you find FluentValidation useful, please consider making a donation. &lt;br /&gt;&lt;a href="http://www.pledgie.com/campaigns/8403"&gt;&lt;img style="border:none;" src="http://www.pledgie.com/campaigns/8403.png?skin_name=chrome" alt="Donate to FluentValidation" title="Donate to FluentValidation" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NuGet packages are available&lt;/b&gt; - the package IDs are FluentValidation, FluentValidation.MVC3 and FluentValidation.MVC4.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;If you need signed binaries&lt;/b&gt; then use the NuGet packages FluentValidaiton-signed, FluentValidation.MVC3-signed and FluentValidation.MVC4-signed.&lt;br /&gt;&lt;br /&gt;The main source code repository for this project is &lt;a href="http://github.com/JeremySkinner/FluentValidation"&gt;on GitHub&lt;/a&gt; although it is also mirrored to CodePlex. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Example&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; FluentValidation;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; CustomerValidator: AbstractValidator&amp;lt;Customer&amp;gt; {
  &lt;span style="color:Blue;"&gt;public&lt;/span&gt; CustomerValidator() {
    RuleFor(customer =&amp;gt; customer.Surname).NotEmpty();
    RuleFor(customer =&amp;gt; customer.Forename).NotEmpty().WithMessage(&lt;span style="color:#A31515;"&gt;&amp;quot;Please specify a first name&amp;quot;&lt;/span&gt;);
    RuleFor(customer =&amp;gt; customer.Company).NotNull();
    RuleFor(customer =&amp;gt; customer.Discount).NotEqual(0).When(customer =&amp;gt; customer.HasDiscount);
    RuleFor(customer =&amp;gt; customer.Address).Length(20, 250);
    RuleFor(customer =&amp;gt; customer.Postcode).Must(BeAValidPostcode).WithMessage(&lt;span style="color:#A31515;"&gt;&amp;quot;Please specify a valid postcode&amp;quot;&lt;/span&gt;);
  }

  &lt;span style="color:Blue;"&gt;private&lt;/span&gt; &lt;span style="color:Blue;"&gt;bool&lt;/span&gt; BeAValidPostcode(&lt;span style="color:Blue;"&gt;string&lt;/span&gt; postcode) {
    &lt;span style="color:Green;"&gt;// custom postcode validating logic goes here&lt;/span&gt;
  }
}

Customer customer = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Customer();
CustomerValidator validator = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; CustomerValidator();
ValidationResult results = validator.Validate(customer);

&lt;span style="color:Blue;"&gt;bool&lt;/span&gt; validationSucceeded = results.IsValid;
IList&amp;lt;ValidationFailure&amp;gt; failures = results.Errors;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Supported By&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http&amp;#58;&amp;#47;&amp;#47;www.jetbrains.com&amp;#47;resharper"&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=FluentValidation&amp;DownloadId=304536" alt="ReSharper" title="ReSharper" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Mon, 29 Apr 2013 16:29:36 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20130429042936P</guid></item><item><title>Updated Wiki: Home</title><link>https://fluentvalidation.codeplex.com/wikipage?version=35</link><description>&lt;div class="wikidoc"&gt;&lt;b&gt;Project Description&lt;/b&gt;&lt;br /&gt;A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules for your business objects. &lt;br /&gt;&lt;br /&gt;If you find FluentValidation useful, please consider making a donation. &lt;br /&gt;&lt;a href="http://www.pledgie.com/campaigns/8403"&gt;&lt;img style="border:none;" src="http://www.pledgie.com/campaigns/8403.png?skin_name=chrome" alt="Donate to FluentValidation" title="Donate to FluentValidation" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NuGet packages are available&lt;/b&gt; - the package IDs are FluentValidation, FluentValidation.MVC3 and FluentValidation.MVC4.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;If you need signed binaries&lt;/b&gt; then use the NuGet packages FluentValidaiton-signed, FluentValidation.MVC3-signed and FluentValidation.MVC4-signed.&lt;br /&gt;&lt;br /&gt;The main source code repository for this project is &lt;a href="http://github.com/JeremySkinner/FluentValidation"&gt;on GitHub&lt;/a&gt; although it is also mirrored to CodePlex. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Example&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; FluentValidation;

&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; CustomerValidator: AbstractValidator&amp;lt;Customer&amp;gt; {
  &lt;span style="color:Blue;"&gt;public&lt;/span&gt; CustomerValidator() {
    RuleFor(customer =&amp;gt; customer.Surname).NotEmpty();
    RuleFor(customer =&amp;gt; customer.Forename).NotEmpty().WithMessage(&lt;span style="color:#A31515;"&gt;&amp;quot;Please specify a first name&amp;quot;&lt;/span&gt;);
    RuleFor(customer =&amp;gt; customer.Company).NotNull();
    RuleFor(customer =&amp;gt; customer.Discount).NotEqual(0).When(customer =&amp;gt; customer.HasDiscount);
    RuleFor(customer =&amp;gt; customer.Address).Length(20, 250);
    RuleFor(customer =&amp;gt; customer.Postcode).Must(BeAValidPostcode).WithMessage(&lt;span style="color:#A31515;"&gt;&amp;quot;Please specify a valid postcode&amp;quot;&lt;/span&gt;);
  }

  &lt;span style="color:Blue;"&gt;private&lt;/span&gt; &lt;span style="color:Blue;"&gt;bool&lt;/span&gt; BeAValidPostcode(&lt;span style="color:Blue;"&gt;string&lt;/span&gt; postcode) {
    &lt;span style="color:Green;"&gt;// custom postcode validating logic goes here&lt;/span&gt;
  }
}

Customer customer = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Customer();
CustomerValidator validator = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; CustomerValidator();
ValidationResult results = validator.Validate(customer);

&lt;span style="color:Blue;"&gt;bool&lt;/span&gt; validationSucceeded = results.IsValid;
IList&amp;lt;ValidationFailure&amp;gt; failures = results.Errors;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;a href="https://fluentvalidation.codeplex.com/documentation?referringTitle=Home"&gt;Documentation&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Supported By&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http&amp;#58;&amp;#47;&amp;#47;www.jetbrains.com&amp;#47;resharper"&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=FluentValidation&amp;DownloadId=304536" alt="ReSharper" title="ReSharper" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Mon, 29 Apr 2013 16:29:20 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20130429042920P</guid></item><item><title>Updated Wiki: CreatingAValidator</title><link>https://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;version=17</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Creating a Validator class&lt;/h1&gt;
Before creating any validators, you will need to add a reference to &lt;b&gt;FluentValidation.dll&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;To define a set of validation rules for a particular object, you will need to create a class that inherits from &lt;b&gt;AbstractValidator&amp;lt;T&amp;gt;&lt;/b&gt;, where T is the type of class that you wish to validate. &lt;br /&gt;&lt;br /&gt;For example, imagine that you have a &lt;b&gt;Customer&lt;/b&gt; class:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class Customer {
  public int Id { get; set; }
  public string Surname { get; set; }
  public string Forename { get; set; }
  public decimal Discount { get; set; }
  public string Address { get; set; }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You would define a set of validation rules for this class by inheriting from &lt;b&gt;AbstractValidator&amp;lt;Customer&amp;gt;&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
using FluentValidation; 

public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The validation rules themselves should be defined in the validator class&amp;#39;s constructor. To specify a validation rule for a particular property, call the &lt;b&gt;RuleFor&lt;/b&gt; method, passing a lambda expression for the property that you wish to validate. For example, to ensure that the &lt;b&gt;Surname&lt;/b&gt; property is not null, the validator class would look like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
using FluentValidation;

public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
  public CustomerValidator {
    RuleFor(customer =&amp;gt; customer.Surname).NotNull();
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="Chaining"&gt;&lt;/a&gt;
&lt;h2&gt;Chaining Validators for the Same Property&lt;/h2&gt;
You can chain multiple validators together for the same property:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
using FluentValidation;

public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
  public CustomerValidator {
    RuleFor(customer =&amp;gt; customer.Surname).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This would ensure that the surname is not null and is not equal to the string &amp;#39;foo&amp;#39;. &lt;br /&gt;&lt;br /&gt;To execute the validator, create an instance of the validator class and pass the object that you wish to validate to the &lt;b&gt;Validate&lt;/b&gt; method.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
Customer customer = new Customer();
CustomerValidator validator = new CustomerValidator();

ValidationResult results = validator.Validate(customer);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="ValidationResult"&gt;&lt;/a&gt;
&lt;h2&gt;ValidationResult&lt;/h2&gt;
The Validate method returns a ValidationResult object. This contains two properties: 
&lt;ul&gt;&lt;li&gt;IsValid - a boolean that says whether the validation suceeded.&lt;/li&gt;
&lt;li&gt;Errors - a collection of ValidationFailure objects containing details about any validation failures. &lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;The following code would write any validation failures to the console:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
Customer customer = new Customer();
CustomerValidator validator = new CustomerValidator();

ValidationResult results = validator.Validate(customer);

if(! results.IsValid) {
  foreach(var failure in results.Errors) {
    Console.WriteLine(&amp;quot;Property &amp;quot; + failure.PropertyName + &amp;quot; failed validation. Error was: &amp;quot; + failure.ErrorMessage);
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="ValidateAndThrow"&gt;&lt;/a&gt;
&lt;h2&gt;Throwing Exceptions&lt;/h2&gt;Instead of returning a ValidationResult, you can alternatively tell FluentValidation to throw an exception if validation fails by using the ValidateAndthrow method:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
Customer customer = new Customer();
CustomerValidator validator = new CustomerValidator();

validator.ValidateAndThrow(customer);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This throws a ValidationException which contains the error messages in the Errors property. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; ValidateAndThrow is an extension method, so you must have the &lt;span class="codeInline"&gt;FluentValidation&lt;/span&gt; namespace imported for this method to be available. &lt;br /&gt;&lt;br /&gt;&lt;a name="ReusingValidators"&gt;&lt;/a&gt;
&lt;h2&gt;Re-using Validators for Complex Properties&lt;/h2&gt;
Validators can be re-used for complex properties. For example, imagine you have two classes, &lt;b&gt;Customer&lt;/b&gt; and &lt;b&gt;Address&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class Customer {
  public string Name { get; set; }
  public Address Address { get; set; }
}

public class Address {
  public string Line1 { get; set; }
  public string Line2 { get; set; }
  public string Town { get; set; }
  public string County { get; set; }
  public string Postcode { get; set; }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;... and you define an AddressValidator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class AddressValidator : AbstractValidator&amp;lt;Address&amp;gt; {
  public AddressValidator() {
    RuleFor(address =&amp;gt; address.Postcode).NotNull();
    //etc
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;... you can then re-use the AddressValidator in the CustomerValidator definition:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
  public CustomerValidator() {
    RuleFor(customer =&amp;gt; customer.Name).NotNull();
    RuleFor(customer =&amp;gt; customer.Address).SetValidator(new AddressValidator())
  }
} 
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;... so when you call &lt;b&gt;Validate&lt;/b&gt; on the CustomerValidator it will run through the validators defined in both the CustomerValidator and the AddressValidator and combine the results into a single ValidationResult. &lt;br /&gt;&lt;br /&gt;&lt;a name="Collections"&gt;&lt;/a&gt;
&lt;h2&gt;Re-using Validators for Collections&lt;/h2&gt;
Validators can also be re-used on properties that contain collections of other objects. For example, imagine a Customer object that has a collection of Orders:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class Customer {
   public IList&amp;lt;Order&amp;gt; Orders { get; set; }
}

public class Order {
  public string ProductName { get; set; }
  public decimal? Cost { get; set; }
}

var customer = new Customer();
customer.Orders = new List&amp;lt;Order&amp;gt; {
  new Order { ProductName = &amp;quot;Foo&amp;quot; },
  new Order { Cost = 5 } 
};

&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;... and you&amp;#39;ve already defined an OrderValidator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class OrderValidator : AbstractValidator&amp;lt;Order&amp;gt; {
    public OrderValidator() {
        RuleFor(x =&amp;gt; x.ProductName).NotNull();
        RuleFor(x =&amp;gt; x.Cost).GreaterThan(0);
    }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;....this validator can be used within the CustomerValidator definition:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
    public CustomerValidator() {
        RuleFor(x =&amp;gt; x.Orders).SetCollectionValidator(new OrderValidator());
    }
}

var validator = new CustomerValidator();
var results = validator.Validate(customer);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;When the validator is executed, the error messages will reflect the placement of the order object within the collection:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
foreach(var result in results.Errors) {
   Console.WriteLine(&amp;quot;Property name: &amp;quot; + result.PropertyName);
   Console.WriteLine(&amp;quot;Error: &amp;quot; + result.ErrorMessage);
   Console.WriteLine(&amp;quot;&amp;quot;);
}
&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;
Property name: Orders[0].Cost
Error: &amp;#39;Cost&amp;#39; must be greater than &amp;#39;0&amp;#39;.

Property name: Orders[1].ProductName
Error: &amp;#39;Product Name&amp;#39; must not be empty.
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can optionally include or exclude certain items in the collection from being validated by using the &lt;i&gt;Where&lt;/i&gt; method:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
 RuleFor(x =&amp;gt; x.Orders).SetCollectionValidator(new OrderValidator())
        .Where(x =&amp;gt; x.Cost != null);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="RuleSets"&gt;&lt;/a&gt;
&lt;h2&gt;Rule Sets&lt;/h2&gt;
RuleSets allow you to group validation rules together which can be executed together as a group whilst ignoring other rules:&lt;br /&gt;&lt;br /&gt;For example, let’s imagine we have 3 properties on a Person object (Id, Surname and Forename) and have a validation rule for each. We could group the Surname and Forename rules together in a “Names” RuleSet:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
 public class PersonValidator : AbstractValidator&amp;lt;Person&amp;gt; {
  public PersonValidator() {
     RuleSet(&amp;quot;Names&amp;quot;, () =&amp;gt; {
        RuleFor(x =&amp;gt; x.Surname).NotNull();
        RuleFor(x =&amp;gt; x.Forename).NotNull();
     });
 
     RuleFor(x =&amp;gt; x.Id).NotEqual(0);
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here the two rules on Surname and Forename are grouped together in a “Names” RuleSet. We can invoke only these rules by passing a ruleSet parameter to the Validate extension method (note that this must be a named parameter as this overload has several options available).&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
 var validator = new PersonValidator();
var person = new Person();
var result = validator.Validate(person, ruleSet: &amp;quot;Names&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This allows you to break down a complex validator definition into smaller segments that can be executed in isolation.&lt;br /&gt;&lt;br /&gt;Additionally, you can execute multiple rulesets by using a comma-separated list of strings:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
validator.Validate(person, ruleSet: &amp;quot;Names,MyRuleSet,SomeOtherRuleSet&amp;quot;)
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;...and you can also include rules not in any ruleset by specifying a ruleset of &amp;quot;default&amp;quot;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
validator.Validate(person, ruleSet: &amp;quot;default,MyRuleSet&amp;quot;)
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This would execute rules in the MyRuleSet set, and those rules not in any ruleset.&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Tue, 23 Apr 2013 13:02:05 GMT</pubDate><guid isPermaLink="false">Updated Wiki: CreatingAValidator 20130423010205P</guid></item><item><title>Updated Wiki: CreatingAValidator</title><link>http://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;version=16</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Creating a Validator class&lt;/h1&gt;
Before creating any validators, you will need to add a reference to &lt;b&gt;FluentValidation.dll&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;To define a set of validation rules for a particular object, you will need to create a class that inherits from &lt;b&gt;AbstractValidator&amp;lt;T&amp;gt;&lt;/b&gt;, where T is the type of class that you wish to validate. &lt;br /&gt;&lt;br /&gt;For example, imagine that you have a &lt;b&gt;Customer&lt;/b&gt; class:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class Customer {
  public int Id { get; set; }
  public string Surname { get; set; }
  public string Forename { get; set; }
  public decimal Discount { get; set; }
  public string Address { get; set; }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You would define a set of validation rules for this class by inheriting from &lt;b&gt;AbstractValidator&amp;lt;Customer&amp;gt;&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
using FluentValidation; 

public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The validation rules themselves should be defined in the validator class&amp;#39;s constructor. To specify a validation rule for a particular property, call the &lt;b&gt;RuleFor&lt;/b&gt; method, passing a lambda expression for the property that you wish to validate. For example, to ensure that the &lt;b&gt;Surname&lt;/b&gt; property is not null, the validator class would look like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
using FluentValidation;

public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
  public CustomerValidator {
    RuleFor(customer =&amp;gt; customer.Surname).NotNull();
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="Chaining"&gt;&lt;/a&gt;
&lt;h2&gt;Chaining Validators for the Same Property&lt;/h2&gt;
You can chain multiple validators together for the same property:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
using FluentValidation;

public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
  public CustomerValidator {
    RuleFor(customer =&amp;gt; customer.Surname).NotNull().NotEqual(&amp;quot;foo&amp;quot;);
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This would ensure that the surname is not null and is not equal to the string &amp;#39;foo&amp;#39;. &lt;br /&gt;&lt;br /&gt;To execute the validator, create an instance of the validator class and pass the object that you wish to validate to the &lt;b&gt;Validate&lt;/b&gt; method.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
Customer customer = new Customer();
CustomerValidator validator = new CustomerValidator();

ValidationResult results = validator.Validate(customer);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="ValidationResult"&gt;&lt;/a&gt;
&lt;h2&gt;ValidationResult&lt;/h2&gt;
The Validate method returns a ValidationResult object. This contains two properties: 
&lt;ul&gt;&lt;li&gt;IsValid - a boolean that says whether the validation suceeded.&lt;/li&gt;
&lt;li&gt;Errors - a collection of ValidationFailure objects containing details about any validation failures. &lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;The following code would write any validation failures to the console:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
Customer customer = new Customer();
CustomerValidator validator = new CustomerValidator();

ValidationResult results = validator.Validate(customer);

if(! results.IsValid) {
  foreach(var failure in results.Errors) {
    Console.WriteLine(&amp;quot;Property &amp;quot; + failure.PropertyName + &amp;quot; failed validation. Error was: &amp;quot; + failure.ErrorMessage);
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="ValidateAndThrow"&gt;&lt;/a&gt;
&lt;h2&gt;Throwing Exceptions&lt;/h2&gt;Instead of returning a ValidationResult, you can alternatively tell FluentValidation to throw an exception if validation fails by using the ValidateAndthrow method:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
Customer customer = new Customer();
CustomerValidator validator = new CustomerValidator();

validator.ValidateAndThrow(customer);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This throws a ValidationException which contains the error messages in the Errors property. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; ValidateAndThrow is an extension method, so you must have the &lt;span class="codeInline"&gt;FluentValidation&lt;/span&gt; namespace imported for this method to be available. &lt;br /&gt;&lt;br /&gt;&lt;a name="ReusingValidators"&gt;&lt;/a&gt;
&lt;h2&gt;Re-using Validators for Complex Properties&lt;/h2&gt;
Validators can be re-used for complex properties. For example, imagine you have two classes, &lt;b&gt;Customer&lt;/b&gt; and &lt;b&gt;Address&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class Customer {
  public string Name { get; set; }
  public Address Address { get; set; }
}

public class Address {
  public string Line1 { get; set; }
  public string Line2 { get; set; }
  public string Town { get; set; }
  public string County { get; set; }
  public string Postcode { get; set; }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;... and you define an AddressValidator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class AddressValidator : AbstractValidator&amp;lt;Address&amp;gt; {
  public AddressValidator() {
    RuleFor(address =&amp;gt; address.Postcode).NotNull();
    //etc
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;... you can then re-use the AddressValidator in the CustomerValidator definition:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
  public CustomerValidator() {
    RuleFor(customer =&amp;gt; customer.Name).NotNull();
    RuleFor(customer =&amp;gt; customer.Address).SetValidator(new AddressValidator())
  }
} 
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;... so when you call &lt;b&gt;Validate&lt;/b&gt; on the CustomerValidator it will run through the validators defined in both the CustomerValidator and the AddressValidator and combine the results into a single ValidationResult. &lt;br /&gt;&lt;br /&gt;&lt;a name="Collections"&gt;&lt;/a&gt;
&lt;h2&gt;Re-using Validators for Collections&lt;/h2&gt;
Validators can also be re-used on properties that contain collections of other objects. For example, imagine a Customer object that has a collection of Orders:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class Customer {
   public IList&amp;lt;Order&amp;gt; Orders { get; set; }
}

public class Order {
  public string ProductName { get; set; }
  public decimal? Cost { get; set; }
}

var customer = new Customer();
customer.Orders = new List&amp;lt;Order&amp;gt; {
  new Order { ProductName = &amp;quot;Foo&amp;quot; },
  new Order { Cost = 5 } 
};

&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;... and you&amp;#39;ve already defined an OrderValidator:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class OrderValidator : AbstractValidator&amp;lt;Order&amp;gt; {
    public OrderValidator() {
        RuleFor(x =&amp;gt; x.ProductName).NotNull();
        RuleFor(x =&amp;gt; x.Cost).GreaterThan(0);
    }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;....this validator can be used within the CustomerValidator definition:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
public class CustomerValidator : AbstractValidator&amp;lt;Customer&amp;gt; {
    public CustomerValidator() {
        RuleFor(x =&amp;gt; x.Orders).SetCollectionValidator(new OrderValidator());
    }
}

var validator = new CustomerValidator();
var results = validator.Validate(customer);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;When the validator is executed, the error messages will reflect the placement of the order object within the collection:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
foreach(var result in results.Errors) {
   Console.WriteLine(&amp;quot;Property name: &amp;quot; + result.PropertyName);
   Console.WriteLine(&amp;quot;Error: &amp;quot; + result.ErrorMessage);
   Console.WriteLine(&amp;quot;&amp;quot;);
}
&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;
Property name: Orders[0].Cost
Error: &amp;#39;Cost&amp;#39; must be greater than &amp;#39;0&amp;#39;.

Property name: Orders[1].ProductName
Error: &amp;#39;Product Name&amp;#39; must not be empty.
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can optionally include or exclude certain items in the collection from being validated by using the &lt;i&gt;Where&lt;/i&gt; method:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
 RuleFor(x =&amp;gt; x.Orders).SetCollectionValidator(new OrderValidator())
        .Where(x =&amp;gt; x.Cost != null);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="RuleSets"&gt;&lt;/a&gt;
&lt;h2&gt;Rule Sets&lt;/h2&gt;
RuleSets allow you to group validation rules together which can be executed together as a group whilst ignoring other rules:&lt;br /&gt;&lt;br /&gt;For example, let’s imagine we have 3 properties on a Person object (Id, Surname and Forename) and have a validation rule for each. We could group the Surname and Forename rules together in a “Names” RuleSet:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
 public class PersonValidator : AbstractValidator&amp;lt;Person&amp;gt; {
  public PersonValidator() {
     RuleSet(&amp;quot;Names&amp;quot;, () =&amp;gt; {
        RuleFor(x =&amp;gt; x.Surname).NotNull();
        RuleFor(x =&amp;gt; x.Forename).NotNull();
     });
 
     RuleFor(x =&amp;gt; x.Id).NotEqual(0);
  }
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here the two rules on Surname and Forename are grouped together in a “Names” RuleSet. We can invoke only these rules by passing a ruleSet parameter to the Validate extension method (note that this must be a named parameter as this overload has several options available).&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;
 var validator = new PersonValidator();
var person = new Person();
var result = validator.Validate(person, ruleSet: &amp;quot;Names&amp;quot;);
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This allows you to break down a complex validator definition into smaller segments that can be executed in isolation.&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>JeremyS</author><pubDate>Mon, 11 Mar 2013 16:33:41 GMT</pubDate><guid isPermaLink="false">Updated Wiki: CreatingAValidator 20130311043341P</guid></item><item><title>New Comment on "CreatingAValidator"</title><link>http://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;ANCHOR#C26807</link><description>Please do not post comments on these wiki pages - they are not monitored. If you have a question, please open a discussion on the Discussions page.</description><author>JeremyS</author><pubDate>Fri, 08 Mar 2013 09:31:27 GMT</pubDate><guid isPermaLink="false">New Comment on "CreatingAValidator" 20130308093127A</guid></item><item><title>New Comment on "CreatingAValidator"</title><link>http://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;ANCHOR#C26794</link><description>I don&amp;#39;t see the .ValidateAndThrow&amp;#40;&amp;#41; method, I&amp;#39;m using FluentValidation.dll version 3.4.6.0.   Could you fix it&amp;#63;</description><author>saranroyal</author><pubDate>Thu, 07 Mar 2013 05:04:14 GMT</pubDate><guid isPermaLink="false">New Comment on "CreatingAValidator" 20130307050414A</guid></item><item><title>New Comment on "CreatingAValidator"</title><link>http://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;ANCHOR#C26019</link><description>RuleFor&amp;#40;x &amp;#61;&amp;#62; x.Orders&amp;#41;.SetCollectionValidator&amp;#40;new OrderValidator&amp;#40;&amp;#41;&amp;#41;&amp;#10;        .Where&amp;#40;x &amp;#61;&amp;#62; x.Cost &amp;#33;&amp;#61; null&amp;#41;&amp;#59;&amp;#10;Is that means only set validator for orders which cost is not null&amp;#63; if so, move &amp;#39;Where&amp;#39; statement in front may be a better choice&amp;#63;</description><author>lurongkai</author><pubDate>Wed, 26 Dec 2012 08:43:33 GMT</pubDate><guid isPermaLink="false">New Comment on "CreatingAValidator" 20121226084333A</guid></item><item><title>New Comment on "mvc"</title><link>http://fluentvalidation.codeplex.com/wikipage?title=mvc&amp;ANCHOR#C25179</link><description>How do you enable client-side validation&amp;#63;  I have integrated FluentValidation with MVC, but it would be great to see how to enforce certain rules on the client without having to post to the server.</description><author>grandadmiralmcb</author><pubDate>Thu, 04 Oct 2012 17:44:07 GMT</pubDate><guid isPermaLink="false">New Comment on "mvc" 20121004054407P</guid></item><item><title>New Comment on "CreatingAValidator"</title><link>http://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;ANCHOR#C24838</link><description>Add information to this documentation page that you have to include the &amp;#34;DefaultValidatorExtensions&amp;#34; for some methods like ValidateAndThrow&amp;#40;&amp;#41;.</description><author>stefh</author><pubDate>Wed, 29 Aug 2012 12:06:21 GMT</pubDate><guid isPermaLink="false">New Comment on "CreatingAValidator" 20120829120621P</guid></item><item><title>New Comment on "CreatingAValidator"</title><link>http://fluentvalidation.codeplex.com/wikipage?title=CreatingAValidator&amp;ANCHOR#C24819</link><description>Very good post for beginner, Thank you.</description><author>Flyear</author><pubDate>Sun, 26 Aug 2012 02:54:26 GMT</pubDate><guid isPermaLink="false">New Comment on "CreatingAValidator" 20120826025426A</guid></item></channel></rss>