Beispiel #1
0
        /// <summary>
        /// 获取属性的ValidBox
        /// </summary>
        /// <param name="property">属性</param>
        /// <param name="message">初始化提示消息</param>
        /// <returns></returns>
        private static ValidBox GetPropertyValidBox(PropertyInfo property, string message)
        {
            var validBox = ValidBox.Empty(message);

            // 值类型非空检测
            if (property.PropertyType.IsValueType && Attribute.IsDefined(property, typeof(RequiredAttribute)) == false)
            {
                validBox = ValidBox.Request(null);
            }

            var boxs = Attribute.GetCustomAttributes(property, false)
                       .Where(item => item is IValidRule)
                       .Cast <IValidRule>()
                       .OrderBy(item => item.OrderIndex)
                       .Select(item => item.ToValidBox());

            foreach (var box in boxs)
            {
                validBox = ValidBox.Merge(validBox, box);
            }

            // 数字类型输入检测
            if (property.PropertyType.IsNumberType() == true)
            {
                validBox = ValidBox.Merge(validBox, ValidBox.New("number", null));
            }
            return(validBox);
        }
Beispiel #2
0
        /// <summary>
        /// 验证输入是URL
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="errorMessage">提示信息</param>
        /// <returns></returns>
        public static ValidBox Url(this ValidBox box, string errorMessage)
        {
            var newBox = new UrlAttribute {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #3
0
        /// <summary>
        /// 验证输入是否是Email
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="errorMessage">提示信息</param>
        /// <returns></returns>
        public static ValidBox Email(this ValidBox box, string errorMessage)
        {
            var newBox = new EmailRule {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #4
0
        /// <summary>
        /// 验证输入的值的范围
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="minValue">最小值</param>
        /// <param name="maxValue">最大值</param>
        /// <param name="errorMessage">提示信息</param>
        /// <returns></returns>
        public static ValidBox Range(this ValidBox box, double minValue, double maxValue, string errorMessage)
        {
            var newBox = new RangeAttribute(minValue, maxValue)
            {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #5
0
        /// <summary>
        /// 验证输入的长度
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="minLength">最小长度</param>
        /// <param name="maxLength">最大长度</param>
        /// <param name="errorMessage">提示信息</param>
        /// <returns></returns>
        public static ValidBox Length(this ValidBox box, int minLength, int maxLength, string errorMessage)
        {
            var newBox = new LengthAttribute(minLength, maxLength)
            {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #6
0
        /// <summary>
        /// 验证输入是否为数字类型
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="errorMessage">错误提示消息</param>
        /// <returns></returns>
        public static ValidBox Number(this ValidBox box, string errorMessage)
        {
            var newBox = new NumberRule()
            {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #7
0
        /// <summary>
        /// 验证输入的值的范围
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="minValue">最小值</param>
        /// <param name="maxValue">最大值</param>
        /// <param name="errorMessage">提示信息</param>
        /// <returns></returns>
        public static ValidBox Range(this ValidBox box, int minValue, int maxValue, string errorMessage)
        {
            var newBox = new RangeRule(minValue, maxValue)
            {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #8
0
        /// <summary>
        /// 验证输入和正则表达式不匹配
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="regexPattern">表达式</param>
        /// <param name="errorMessage">提示信息</param>
        /// <returns></returns>
        public static ValidBox NotMatch(this ValidBox box, string regexPattern, string errorMessage)
        {
            var newBox = new NotMatchRule(regexPattern)
            {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #9
0
        /// <summary>
        /// 验证精度(小数点数)
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="min">最小精度</param>
        /// <param name="max">最大精度</param>
        /// <param name="errorMessage">提示信息</param>
        /// <returns></returns>
        public static ValidBox Precision(this ValidBox box, int min, int max, string errorMessage)
        {
            var newBox = new PrecisionRule(min, max)
            {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #10
0
        /// <summary>
        /// 验证输入是否和目标ID元素的值不相等
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="targetID">目标元素ID</param>
        /// <param name="errorMessage">提示信息</param>
        /// <returns></returns>
        public static ValidBox NotEqualTo(this ValidBox box, string targetID, string errorMessage)
        {
            var newBox = new NotEqualToRule(targetID)
            {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #11
0
        /// <summary>
        /// 验证输入的最大长度
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="length">最大长度</param>
        /// <param name="errorMessage">提示信息</param>
        /// <returns></returns>
        public static ValidBox MaxLength(this ValidBox box, int length, string errorMessage)
        {
            var newBox = new MaxLengthRule(length)
            {
                ErrorMessage = errorMessage
            }.ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #12
0
        /// <summary>
        /// 验证输入是否和目标ID元素的值不相等
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="targetID">目标元素ID</param>
        /// <returns></returns>
        public static ValidBox NotEqualTo(this ValidBox box, string targetID)
        {
            var newBox = new NotEqualToRule(targetID).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #13
0
        /// <summary>
        /// 验证输入和正则表达式不匹配
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="regexPattern">表达式</param>
        /// <returns></returns>
        public static ValidBox NotMatch(this ValidBox box, string regexPattern)
        {
            var newBox = new NotMatchRule(regexPattern).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #14
0
        /// <summary>
        /// 验证精度(小数点数)
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="min">最小精度</param>
        /// <param name="max">最大精度</param>
        /// <returns></returns>
        public static ValidBox Precision(this ValidBox box, int min, int max)
        {
            var newBox = new PrecisionRule(min, max).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #15
0
        /// <summary>
        /// 验证输入是否为数字类型
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="errorMessage">错误提示消息</param>
        /// <returns></returns>
        public static ValidBox Number(this ValidBox box, string errorMessage)
        {
            var newBox = ValidBox.New("number", errorMessage);

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #16
0
        /// <summary>
        /// 验证输入是否为数字类型
        /// </summary>
        /// <param name="box">验证框</param>
        /// <returns></returns>
        public static ValidBox Number(this ValidBox box)
        {
            var newBox = new NumberRule().ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #17
0
        /// <summary>
        /// 验证输入的最小长度
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="length">最小长度</param>
        /// <returns></returns>
        public static ValidBox MinLength(this ValidBox box, int length)
        {
            var newBox = new MinLengthAttribute(length).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #18
0
        /// <summary>
        /// 验证输入的最大长度
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="length">最大长度</param>
        /// <returns></returns>
        public static ValidBox MaxLength(this ValidBox box, int length)
        {
            var newBox = new MaxLengthRule(length).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #19
0
        /// <summary>
        /// 验证输入的长度
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="minLength">最小长度</param>
        /// <param name="maxLength">最大长度</param>
        /// <returns></returns>
        public static ValidBox Length(this ValidBox box, int minLength, int maxLength)
        {
            var newBox = new LengthRule(minLength, maxLength).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #20
0
        /// <summary>
        /// 验证输入的值的范围
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="minValue">最小值</param>
        /// <param name="maxValue">最大值</param>
        /// <returns></returns>
        public static ValidBox Range(this ValidBox box, double minValue, double maxValue)
        {
            var newBox = new RangeAttribute(minValue, maxValue).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #21
0
        /// <summary>
        /// 验证和正则表达式是否匹配
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="regexPattern">表达式</param>
        /// <returns></returns>
        public static ValidBox Match(this ValidBox box, string regexPattern)
        {
            var newBox = new MatchAttribute(regexPattern).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #22
0
        /// <summary>
        /// 验证输入是否是Email
        /// </summary>
        /// <param name="box">验证框</param>
        /// <returns></returns>
        public static ValidBox Email(this ValidBox box)
        {
            var newBox = new EmailRule().ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #23
0
        /// <summary>
        /// 远程验证输入值
        /// 不支持后台验证功能
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="url">远程地址</param>
        /// <param name="targetID">提交的目标元素的ID</param>
        /// <returns></returns>
        public static ValidBox Remote(this ValidBox box, string url, params string[] targetID)
        {
            var newBox = new RemoteRule(url, targetID).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #24
0
        /// <summary>
        /// 验证输入是URL
        /// </summary>
        /// <param name="box">验证框</param>
        /// <returns></returns>
        public static ValidBox Url(this ValidBox box)
        {
            var newBox = new UrlAttribute().ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #25
0
        /// <summary>
        /// 验证输入的值的范围
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="minValue">最小值</param>
        /// <param name="maxValue">最大值</param>
        /// <returns></returns>
        public static ValidBox Range(this ValidBox box, int minValue, int maxValue)
        {
            var newBox = new RangeRule(minValue, maxValue).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #26
0
        /// <summary>
        /// 验证输入是否为数字类型
        /// </summary>
        /// <param name="box">验证框</param>
        /// <returns></returns>
        public static ValidBox Number(this ValidBox box)
        {
            var newBox = ValidBox.New("number", null);

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #27
0
        /// <summary>
        /// 验证必须输入
        /// </summary>
        /// <param name="box">验证框</param>
        /// <returns></returns>
        public static ValidBox Required(this ValidBox box)
        {
            var newBox = new RequiredRule().ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #28
0
        /// <summary>
        /// 验证输入是否和目标ID元素的值相等
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="targetID">目标元素ID</param>
        /// <returns></returns>
        public static ValidBox EqualTo(this ValidBox box, string targetID)
        {
            var newBox = new EqualToAttribute(targetID).ToValidBox();

            return(ValidBox.Merge(box, newBox));
        }