提交
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using Appointment.Entity.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Appointment.Entity.ValidateAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 手机格式校验
|
||||
/// 注意:当存在内容时才校验,如果为必填信息,请同时使用必填特性
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Add:yuangb 2019-3-11
|
||||
/// 使用格式:实体属性前加 [Phone(ErrorMessage = "手机号码不正确")]
|
||||
/// </remarks>
|
||||
public class PhoneAttribute : ValidateAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 报错提示信息
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user