Ok, so I have a WPF Application (using MVVM) consisting of a View that has two textboxes: First Name and Last Name.
Both of them must consist of only letters. I've achieved that by using attributes on the corresponding entity (Worker):
[RegularExpression(@"^[a-zA-Z]+$", ErrorMessage = "First Name must consist of letters only.")]
public string FirstName
[RegularExpression(@"^[a-zA-Z]+$", ErrorMessage = "Last Name must consist of letters only.")]
public string LastName
And it works great. But...I also need to have the following validation rule: At least one of the fields: FirstName or LastName Must be filled.
Any ideas on how to implement validation involving two fields?
The expected result is: If non of the fields is filled, then a validation msg will appear beside the FirstName textbox: At least first name or last name must be filled. The same message will also appear near the the last name textbox. Once I fill one of those fields, Both messages will disppear.
Another challenge, is that if I enter a digit in first name textbox, I want an error message only on the First name textbox: First Name must consist of letters only. And I want the error of at least one of the fields must be filled (near both of the textboxes) to dissapear.
Thanks!