How to validate more than two feilds

Jul 13, 2012 at 3:47 PM

Hi,

please help me how i can validate more than two fields in one rule

thanks

Coordinator
Jul 23, 2012 at 8:51 PM
Edited Jul 23, 2012 at 8:55 PM

Very easy. Here is an example:

Validator.AddRule(() => RangeStart,
                  () => RangeEnd,
                  () => RuleResult.Assert(RangeEnd > RangeStart, "RangeEnd must be grater than RangeStart");

RangeStart and RangeEnd are two different properties. If this rule fails, both properties become invalid.

Jul 31, 2012 at 1:21 PM

Dear Pglazkov

I know that, but i need validate 3 fields and more in one rule.

thanks.

Coordinator
Jul 31, 2012 at 1:30 PM

There is an overload of the AddRule method that takes an enumerable of properties, so you can pass any number of properties to validate. Here is an example:

var propertiesToValidate = new Expression<Func<object>>[]
			   {
				() => Property1, 
				() => Property2,
				() => Property3,
                                ...
			   };

Validator.AddRule(propertiesToValidate,
                  () => /* Here goes validation logic that involves Property1, Property2, Property3, ... */, 
                  "Message that is shown when this rule fails.");

Oct 24, 2013 at 1:54 PM
Edited Oct 24, 2013 at 1:54 PM
not quite nice code but works for me :)
could be a new builtin-feature for the new version?

thanks !
Coordinator
Oct 24, 2013 at 2:26 PM
Yes, will add it in the next version.