34 lines
808 B
C#
34 lines
808 B
C#
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);
|
|
}
|
|
}
|
|
}
|