Ejemplo n.º 1
0
        /// <summary>
        /// 自定义错误
        /// </summary>
        /// <param name="value"></param>
        /// <param name="maxLength"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static VALIDATE CustomerError(string fieldName, string fieldError)
        {
            var vali = new VALIDATE(fieldName);

            vali.ISOK = false;
            vali.MESS = fieldError;
            return(vali);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 区间数
        /// </summary>
        /// <param name="value"></param>
        /// <param name="maxLength"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static VALIDATE ISSection(decimal minValue, decimal maxValue, decimal value, string fieldName)
        {
            var vali = new VALIDATE(fieldName.ToString());

            vali.ISOK = true;
            if (!(value < minValue || value > maxValue))
            {
                vali.ISOK = false;
                vali.MESS = string.Format("字段[{0}]小于{1}或大于{2}", fieldName, minValue, maxValue);
            }
            return(vali);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 不能为空
        /// </summary>
        /// <param name="value"></param>
        /// <param name="maxLength"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static VALIDATE NOTNULL(string value, string fieldName)
        {
            var vali = new VALIDATE(fieldName);

            vali.ISOK = true;
            if (string.IsNullOrEmpty(value))
            {
                vali.ISOK = false;
                vali.MESS = string.Format("字段[{0}]不能为空", fieldName);
            }
            return(vali);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 可以为空且长度不能超过指定长度
        /// </summary>
        /// <param name="value"></param>
        /// <param name="maxLength"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static VALIDATE CANNULLANDLIMITLENGTH(string value, int maxLength, string fieldName)
        {
            var vali = new VALIDATE(fieldName);

            vali.ISOK = true;
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Length > maxLength)
                {
                    vali.ISOK = false;
                    vali.MESS = string.Format("字段[{0}]长度超过最大长度" + maxLength.ToString(), fieldName);
                }
            }
            return(vali);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 是否为空,如果不为空,是否是数字,数字长度必须为一定范围值
        /// </summary>
        /// <param name="value"></param>
        /// <param name="fieldName"></param>
        /// <param name="isNull">true 可以为空 false 不能为空</param>
        /// <param name="isNumber">true 只能为数字 false 可不为数字</param>
        /// <param name="maxLength">不为空最大长度</param>
        /// <param name="minLength">不为空最小长度</param>
        /// <returns></returns>
        public static VALIDATE ORNULLANDNUMBER(string value, string fieldName, bool isNull = true, bool isNumber = true, int maxLength = 8000, int minLength = 0)
        {
            VALIDATE val = new VALIDATE(fieldName);

            val.ISOK = true;

            if (!string.IsNullOrEmpty(value))
            {
                //return Regex.IsMatch(value, @"^[+-]?\d*$");
                bool isOk = Regex.IsMatch(value, @"^\d*$");
                if (isOk)
                {
                    if (value.Length > maxLength || value.Length < minLength)
                    {
                        val.ISOK = false;
                        val.MESS = string.Format("{0}:{1}", fieldName, "长度不能大于:" + maxLength + "且不能小于:" + minLength);
                    }
                }
                else
                {
                    if (!isNumber)
                    {
                        if (value.Length > maxLength || value.Length < minLength)
                        {
                            val.ISOK = false;
                            val.MESS = string.Format("{0}:{1}", fieldName, "长度不能大于:" + maxLength + "且不能小于:" + minLength);
                        }
                    }
                    else
                    {
                        val.ISOK = false;
                        val.MESS = string.Format("{0}:{1}", fieldName, "不为数字");
                    }
                }
            }
            else
            {
                if (!isNull)
                {
                    val.ISOK = false;
                    val.MESS = string.Format("{0}:{1}", fieldName, "不能为空");
                }
            }
            return(val);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 添加验证
 /// </summary>
 /// <param name="vali"></param>
 public void ADD_VALIDATE(VALIDATE vali)
 {
     erro.Add(vali);
 }