You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
using FluentValidation;
|
|
|
|
|
|
|
|
namespace CellularManagement.Application.Features.Users.Commands.UpdateUser;
|
|
|
|
|
|
|
|
public sealed class UpdateUserCommandValidator : AbstractValidator<UpdateUserCommand>
|
|
|
|
{
|
|
|
|
public UpdateUserCommandValidator()
|
|
|
|
{
|
|
|
|
RuleFor(x => x.UserId)
|
|
|
|
.NotEmpty().WithMessage("用户ID不能为空");
|
|
|
|
|
|
|
|
When(x => x.UserName != null, () =>
|
|
|
|
{
|
|
|
|
RuleFor(x => x.UserName)
|
|
|
|
.Length(3, 50).WithMessage("账号长度必须在3-50个字符之间")
|
|
|
|
.Matches("^[a-zA-Z0-9_]+$").WithMessage("账号只能包含字母、数字和下划线");
|
|
|
|
});
|
|
|
|
|
|
|
|
When(x => x.RealName != null, () =>
|
|
|
|
{
|
|
|
|
RuleFor(x => x.RealName)
|
|
|
|
.MaximumLength(50).WithMessage("用户名长度不能超过50个字符");
|
|
|
|
});
|
|
|
|
|
|
|
|
When(x => x.Email != null, () =>
|
|
|
|
{
|
|
|
|
RuleFor(x => x.Email)
|
|
|
|
.EmailAddress().WithMessage("邮箱格式不正确");
|
|
|
|
});
|
|
|
|
|
|
|
|
When(x => x.PhoneNumber != null, () =>
|
|
|
|
{
|
|
|
|
RuleFor(x => x.PhoneNumber)
|
|
|
|
.Matches(@"^1[3-9]\d{9}$").WithMessage("手机号格式不正确");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|