Files
NetAdmin/src/backend/NetAdmin.Domain/Attributes/DataValidation/UserNameAttribute.cs
2024-05-29 15:03:05 +08:00

34 lines
972 B
C#

namespace NetAdmin.Domain.Attributes.DataValidation;
/// <summary>
/// 用户名验证器
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter)]
public sealed class UserNameAttribute : RegexAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="UserNameAttribute" /> class.
/// </summary>
public UserNameAttribute() //
: base(Chars.RGX_USERNAME)
{
ErrorMessageResourceType = typeof(Ln);
}
/// <inheritdoc />
public override bool IsValid(object value)
{
if (!base.IsValid(value)) {
ErrorMessageResourceName = nameof(Ln.4);
return false;
}
if (!new MobileAttribute().IsValid(value)) {
return true;
}
// 不能是手机号码
ErrorMessageResourceName = nameof(Ln.);
return false;
}
}