File size: 1,127 Bytes
bb35ced | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | using FluentValidation;
namespace AiDevProject.Core.Validation;
/// <summary>
/// User creation validator.
/// </summary>
public class CreateUserValidator : AbstractValidator<CreateUserRequest>
{
public CreateUserValidator()
{
RuleFor(x => x.Email)
.NotEmpty().WithMessage("Email is required")
.EmailAddress().WithMessage("Invalid email format");
RuleFor(x => x.Password)
.NotEmpty().WithMessage("Password is required")
.MinimumLength(8).WithMessage("Password must be at least 8 characters")
.Matches(@"[A-Z]").WithMessage("Password must contain uppercase letter")
.Matches(@"[a-z]").WithMessage("Password must contain lowercase letter")
.Matches(@"[0-9]").WithMessage("Password must contain number");
RuleFor(x => x.Name)
.MaximumLength(100).WithMessage("Name too long")
.When(x => !string.IsNullOrEmpty(x.Name));
}
}
/// <summary>
/// User creation request DTO.
/// </summary>
public record CreateUserRequest(
string Email,
string Password,
string? Name = null
);
|