示例#1
0
        /// <summary>
        /// 正则表达式验证
        /// </summary>
        /// <param name="item"></param>
        /// <param name="_Model"></param>
        /// <param name="DisplayName"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool CRegularExpression(PropertyInfo item, T _Model, string DisplayName, object Value)
        {
            if (Value == null)
            {
                return(true);
            }
            //获取有特性标记的属性【正则表达式验证】
            var _Attribute = ReflexHelper.GetAttribute <CRegularExpressionAttribute>(_Model.GetType(), item.Name);

            if (_Attribute != null && !System.Text.RegularExpressions.Regex.IsMatch(Value.ToString(), _Attribute.Pattern))
            {
                return(SetErrorMessage(_Attribute.ErrorMessage, DisplayName + "格式不正确", DisplayName));
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// 字符串长度验证
        /// </summary>
        /// <param name="item"></param>
        /// <param name="_Model"></param>
        /// <param name="DisplayName"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool CStringLength(PropertyInfo item, T _Model, string DisplayName, object Value)
        {
            if (Value == null)
            {
                return(true);
            }
            //获取有特性标记的属性【字符串长度验证】
            var _Attribute = ReflexHelper.GetAttribute <CStringLengthAttribute>(_Model.GetType(), item.Name);

            if (_Attribute != null && (Value.ToString().Length < _Attribute.MinLength || Value.ToString().Length > _Attribute.MaxLength))
            {
                return(SetErrorMessage(_Attribute.ErrorMessage, DisplayName + "长度介于" + _Attribute.MinLength + "-" + _Attribute.MaxLength + "之间", DisplayName));
            }
            return(true);
        }