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.
30 lines
894 B
30 lines
894 B
3 months ago
|
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个字符之间");
|
||
|
});
|
||
|
|
||
|
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("手机号格式不正确");
|
||
|
});
|
||
|
}
|
||
|
}
|