using Appointment.Entity.Utility; using System; using System.Collections.Generic; using System.Text; namespace Appointment.Entity.ValidateAttribute { /// /// 手机格式校验 /// 注意:当存在内容时才校验,如果为必填信息,请同时使用必填特性 /// /// /// Add:yuangb 2019-3-11 /// 使用格式:实体属性前加 [Phone(ErrorMessage = "手机号码不正确")] /// public class PhoneAttribute : ValidateAttribute { /// /// 报错提示信息 /// public string ErrorMessage { get; set; } public override string Validate(object oValue) { if (oValue != null && !string.IsNullOrWhiteSpace(oValue.ToString())) { string sPhone = oValue.ToString().Replace("+86", ""); if (!sPhone.IsPhone()) return ErrorMessage; } return null; } } }