23 lines
659 B
C#
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.");
|
|
}
|
|
}
|