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

> 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?

This is the default behaviour, but you can set the CascadeMode on a rule to tell it to stop processing rules after the first failure. See this page in the docs: http://fluentvalidation.codeplex.com/wikipage?title=Customising&referringTitle=Documentation&ANCHOR#Cascade

> how can i throw one error message for multiple errors? 

Probably the simplest thing is to specify the error message in a variable once, and then use that variable in several WIthMessage calls. 

> how can i do a validation on string values with an OR? like .Equal("T" || "D")?

RuleFor(x => x.SomeProperty).Must(x => x == "T" || x == "D")

Jeremy


Viewing all articles
Browse latest Browse all 1917


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