Search code examples
asp.netvalidationdecimalfluent

How to check the length of decimal types with fluent validation?


I want a decimal type variable to be greater than zero with fluent validation. How can I do this control with fluent validation?

  • Daily rental fee must be greater than zero

*** DailyPrice is decimal type

public class CarValidator : AbstractValidator<Car>
{
    public CarValidator()
    {
        RuleFor(p => p.Name).MinimumLength(2);
        RuleFor(p => p.DailyPrice).MinimumLength(2);
    }
}

Solution

  • Try this:

    RuleFor(p => p.DailyRentalFee).GreaterThan(0);