Skip to content

Instantly share code, notes, and snippets.

@pilotgeraldb
Created July 5, 2022 22:10
Show Gist options
  • Save pilotgeraldb/0faeb4d1bfdef7873370790a143d438b to your computer and use it in GitHub Desktop.
Save pilotgeraldb/0faeb4d1bfdef7873370790a143d438b to your computer and use it in GitHub Desktop.
example_validator
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