Example #1
0
        /// <summary>
        /// 初始化字符串最小长度验证
        /// </summary>
        private static void InitMinLength(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <MinLengthAttribute>();

            if (attribute == null)
            {
                return;
            }
            config.SetAttribute(UiConst.MinLength, attribute.Length);
            config.SetAttribute(UiConst.MinLengthMessage, attribute.ErrorMessage);
        }
Example #2
0
        /// <summary>
        /// 初始化正则表达式验证
        /// </summary>
        private static void InitRegex(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <RegularExpressionAttribute>();

            if (attribute == null)
            {
                return;
            }
            config.SetAttribute(UiConst.Regex, attribute.Pattern);
            config.SetAttribute(UiConst.RegexMessage, attribute.ErrorMessage);
        }
Example #3
0
        /// <summary>
        /// 初始化数值范围验证
        /// </summary>
        private static void InitRange(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <RangeAttribute>();

            if (attribute == null)
            {
                return;
            }
            config.SetAttribute(UiConst.Min, attribute.Minimum);
            config.SetAttribute(UiConst.Max, attribute.Maximum);
            config.SetAttribute(UiConst.MinMessage, attribute.ErrorMessage);
            config.SetAttribute(UiConst.MaxMessage, attribute.ErrorMessage);
        }
Example #4
0
        /// <summary>
        /// 初始化字符串长度验证
        /// </summary>
        private static void InitStringLength(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <StringLengthAttribute>();

            if (attribute == null)
            {
                return;
            }
            if (attribute.MinimumLength > 0)
            {
                config.SetAttribute(UiConst.MinLength, attribute.MinimumLength);
            }
            if (attribute.MaximumLength > 0)
            {
                config.SetAttribute(UiConst.MaxLength, attribute.MaximumLength);
            }
        }
Example #5
0
        /// <summary>
        /// 初始化电子邮件验证
        /// </summary>
        private static void InitEmail(TextBoxConfig config, MemberInfo member)
        {
            var attribute = member.GetCustomAttribute <EmailAddressAttribute>();

            if (attribute == null)
            {
                return;
            }
            config.Email();
            if (attribute.ErrorMessage.Contains("field is not a valid e-mail address"))
            {
                return;
            }
            config.SetAttribute(UiConst.EmailMessage, attribute.ErrorMessage);
        }
Example #6
0
 /// <summary>
 /// 初始化正则表达式验证
 /// </summary>
 private static void InitRegex(TextBoxConfig config, string pattern, string errorMessage)
 {
     config.SetAttribute(UiConst.Regex, pattern);
     config.SetAttribute(UiConst.RegexMessage, errorMessage);
 }