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

New Post: Validation rules for Required fields

$
0
0

I have figured out where the problem is. Changed the order in the rule and validation behaves as expected:

publicclass SampleValidator : AbstractValidator<ValidatableItem>
{public SampleValidator(ValidationConfiguration configuration)
	{
		RuleFor(x => x.ValidatableProperty).Cascade(CascadeMode.StopOnFirstFailure)
			.Length(5, 10).When(item => !string.IsNullOrWhiteSpace(item.ValidatableProperty))
			.NotNull().When(item => configuration.RequiredField)
			.NotEmpty().When(item => configuration.RequiredField);
	}
}

 


Viewing all articles
Browse latest Browse all 1917

Trending Articles



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