diff --git a/src/Application/TakeoutSaaS.Application/App/Tenants/Commands/SelfRegisterTenantCommand.cs b/src/Application/TakeoutSaaS.Application/App/Tenants/Commands/SelfRegisterTenantCommand.cs index 259a004..cddd7ed 100644 --- a/src/Application/TakeoutSaaS.Application/App/Tenants/Commands/SelfRegisterTenantCommand.cs +++ b/src/Application/TakeoutSaaS.Application/App/Tenants/Commands/SelfRegisterTenantCommand.cs @@ -14,6 +14,7 @@ public sealed record SelfRegisterTenantCommand : IRequest /// [Required] [StringLength(64)] + [RegularExpression("^[A-Za-z0-9]+$", ErrorMessage = "登录账号仅允许大小写字母和数字")] public string AdminAccount { get; init; } = string.Empty; /// diff --git a/src/Application/TakeoutSaaS.Application/App/Tenants/Validators/SelfRegisterTenantCommandValidator.cs b/src/Application/TakeoutSaaS.Application/App/Tenants/Validators/SelfRegisterTenantCommandValidator.cs new file mode 100644 index 0000000..411d834 --- /dev/null +++ b/src/Application/TakeoutSaaS.Application/App/Tenants/Validators/SelfRegisterTenantCommandValidator.cs @@ -0,0 +1,22 @@ +using FluentValidation; +using TakeoutSaaS.Application.App.Tenants.Commands; + +namespace TakeoutSaaS.Application.App.Tenants.Validators; + +/// +/// 自助注册租户命令验证器。 +/// +public sealed class SelfRegisterTenantCommandValidator : AbstractValidator +{ + /// + /// 初始化验证规则。 + /// + public SelfRegisterTenantCommandValidator() + { + RuleFor(x => x.AdminAccount) + .NotEmpty() + .MaximumLength(64) + .Matches("^[A-Za-z0-9]+$") + .WithMessage("登录账号仅允许大小写字母和数字"); + } +}