| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 | 
							- using System.ComponentModel.DataAnnotations;
 
- namespace Masuit.Tools.Core.Validator
 
- {
 
-     /// <summary>
 
-     /// 验证手机号码是否合法
 
-     /// </summary>
 
-     public class IsPhoneAttribute : ValidationAttribute
 
-     {
 
-         /// <summary>
 
-         /// 是否允许为空
 
-         /// </summary>
 
-         public bool AllowEmpty { get; set; }
 
-         private readonly string _customMessage;
 
-         public IsPhoneAttribute()
 
-         {
 
-             _customMessage = ErrorMessage;
 
-         }
 
-         /// <summary>
 
-         /// 验证手机号码是否合法
 
-         /// </summary>
 
-         /// <param name="value"></param>
 
-         /// <returns></returns>
 
-         public override bool IsValid(object value)
 
-         {
 
-             if (value is null && !AllowEmpty)
 
-             {
 
-                 ErrorMessage = _customMessage ?? "手机号码不能为空";
 
-                 return false;
 
-             }
 
-             string phone = value as string;
 
-             if (phone.MatchPhoneNumber())
 
-             {
 
-                 return true;
 
-             }
 
-             ErrorMessage = _customMessage ?? "手机号码格式不正确,请输入有效的大陆11位手机号码!";
 
-             return false;
 
-         }
 
-     }
 
- }
 
 
  |