Files
ExpenseTrackerApi/Validators/CreateCategoryDtoValidator.cs
Kevin Harlay ebfaf6f5ec Initial commit
2026-09-07 13:33:22 +02:00

23 lines
659 B
C#

using ExpenseTracker.Api.DTOs;
using FluentValidation;
namespace ExpenseTracker.Api.Validators;
public class CreateCategoryDtoValidator : AbstractValidator<CreateCategoryDto>
{
public CreateCategoryDtoValidator()
{
RuleFor(x => x.Name)
.NotEmpty()
.WithMessage("Name is required.")
.MaximumLength(100)
.WithMessage("Name must not exceed 100 characters.");
RuleFor(x => x.Color)
.NotEmpty()
.WithMessage("Color is required.")
.Matches(@"^#[0-9A-Fa-f]{6}$")
.WithMessage("Color must be a valid hex color in the format #RRGGBB.");
}
}