提交
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Appointment.Entity.ValidateAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 整型数值值范围效验
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Add:yuangb 2019-3-11
|
||||
/// 使用格式:实体属性前加[IntValue(minValue: 1000, maxValue: 999999, ErrorMessage = "验证码长度不正确")]
|
||||
/// </remarks>
|
||||
public class LongValueAttribute : ValidateAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 报错提示
|
||||
/// </summary>
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最小值(包含)
|
||||
/// </summary>
|
||||
public long MinValue { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大值(包含)
|
||||
/// </summary>
|
||||
public long MaxValue { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="minValue">最小值(包含)</param>
|
||||
/// <param name="maxValue">最大值(包含)</param>
|
||||
public LongValueAttribute(long minValue, long maxValue)
|
||||
{
|
||||
this.MinValue = minValue;
|
||||
this.MaxValue = maxValue;
|
||||
}
|
||||
|
||||
public override string Validate(object oValue)
|
||||
{
|
||||
if (oValue != null)
|
||||
{
|
||||
long lValue = Convert.ToInt64(oValue);
|
||||
if (lValue < MinValue || lValue > MaxValue) return ErrorMessage;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user