Created
July 5, 2022 22:10
-
-
Save pilotgeraldb/0faeb4d1bfdef7873370790a143d438b to your computer and use it in GitHub Desktop.
example_validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ModelValidator : AbstractValidator<Model> { | |
public ModelValidator() { | |
RuleFor(x => x.Surname).NotEmpty(); | |
RuleFor(x => x.Forename).NotEmpty().WithMessage("Please specify a first name"); | |
RuleFor(x => x.Discount).NotEqual(0).When(x => x.HasDiscount); | |
RuleFor(x => x.Address).Length(20, 250); | |
RuleFor(x => x.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment