如何在电子邮件或PhoneNumber中编写允许为空的验证规则
RuleFor(x => x.Email).NotEmpty().WithMessage(localizationService.GetResource("ContactUs.Email.Required"));
RuleFor(x => x.PhoneNumber).NotEmpty().WithMessage(localizationService.GetResource("Products.MakeAnOffer.PhoneNumber"));发布于 2017-11-03 15:29:42
试试这个:
RuleFor(x => x.Email)
.NotEmpty()
.When(x => string.IsNullOrEmpty(x.PhoneNumber))//will run only if PhoneNumber is empty
.WithMessage(localizationService.GetResource("ContactUs.Email.Required"));
RuleFor(x => x.PhoneNumber)
.NotEmpty().When(x => string.IsNullOrEmpty(x.Email))//will run only if Email is empty
.WithMessage(localizationService.GetResource("Products.MakeAnOffer.PhoneNumber"));https://stackoverflow.com/questions/47098134
复制相似问题