添加项目文件。
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace IdentityService.Domain.ValueObjects
|
||||
{
|
||||
public class Email
|
||||
{
|
||||
public string Value { get; }
|
||||
public Email(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new ArgumentNullException("邮箱地址不可为空");
|
||||
}
|
||||
|
||||
string pattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
||||
if (!Regex.IsMatch(value, pattern))
|
||||
{
|
||||
throw new ArgumentException("邮箱地址格式不符合要求");
|
||||
}
|
||||
this.Value = value.ToLowerInvariant();
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
public static implicit operator Email(string value)
|
||||
{
|
||||
return new Email(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace IdentityService.Domain.ValueObjects
|
||||
{
|
||||
public class Phone
|
||||
{
|
||||
public string Value { get; }
|
||||
public Phone(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new ArgumentNullException("手机号不可为空");
|
||||
}
|
||||
|
||||
|
||||
string pattern = "^1[3-9]\\d{9}$";
|
||||
if (!Regex.IsMatch(value, pattern))
|
||||
{
|
||||
throw new ArgumentException("手机号格式不符合要求");
|
||||
}
|
||||
Value = value;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
public static implicit operator Phone(string value)
|
||||
{
|
||||
return new Phone(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user