I have an implementation of INotifyDataErrorInfo, which works as I expect it to with Data Annotations, but what I really want to know is how I can do a conditional validation.
Let’s say I have 3 textboxes, Name, Email and Address. I have Name as a required field, but I only require Email OR Address to be entered, and so the validation rule(s) need to check if one of those two properties has a value or not.
Hopefully that makes sense and someone will be able to guide me in the right direction.
Add the attribute:
to the property declarations for
EmailandAddressin the metadata definition of your class. This will allow the string to be empty but when it’s not the normal validation rules will kick in. So if you add the class validator:this can then in this method check that one of these two values has been set.