Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: multiple validation on the same property with message

$
0
0

Hello,

First awsome job on this framework, I'm trying to setup some rules on one propperty. I want it to be not null and one of two string values. For example:

RuleFor(x => x.MyProperty).NotNull(); 
RuleFor(x => x.MyProperty).Equal("G");             
RuleFor(x => x.MyProperty).Equal("N");
I tried to create the rule like this:
RuleFor(x => x.MyProperty)
                .NotNull().WithMessage("MyProperty is required.")
                .Equal("D").WithMessage("Invalid value.")
                .Equal("T").WithMessage("Invalid value.");
 
Here are my questions:
  1. if the first rule fails, why it would still return the following rules as failed as well. if there a way to stop validation when the first rule fails?
  2. how can i throw one error message for multiple errors? 
  3. how can i do a validation on string values with an OR? like .Equal("T" || "D")?

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>