예제 #1
0
        internal static void ValidateMaximumNumericValue(this FormElementElement element)
        {
            string  maximumValue = element.GetAttributeValue("max");
            decimal maximumNumericValue;

            try
            {
                maximumNumericValue = decimal.Parse(maximumValue);
            }
            catch
            {
                return;
            }

            decimal elementValue;

            try
            {
                elementValue = decimal.Parse(element.Value);
            }
            catch
            {
                throw new FormElementValidationException("Invalid element value.");
            }

            if (elementValue > maximumNumericValue)
            {
                throw new FormElementValidationException(string.Format("Value must be less than or equal to {0}.", maximumValue));
            }
        }
예제 #2
0
        /// <summary>
        /// An extension method for minimum length validation
        /// </summary>
        /// <param name="element"></param>
        internal static void ValidateMinimumLength(this FormElementElement element)
        {
            int?minLength = element.ParseNonNegativeIntegerAttribute("minlength", 0);

            if (element.Value.Length < minLength)
            {
                throw new FormElementValidationException(string.Format("Please lengthen this text to {0} characters or more (you are currently using {1} characters)", minLength, element.Value.Length));
            }
        }
예제 #3
0
        internal static void ValidatePattern(this FormElementElement element)
        {
            string pattern = element.GetAttributeValue("pattern");

            if (!string.IsNullOrWhiteSpace(pattern))
            {
                Regex           expression = new Regex(pattern);
                MatchCollection matches    = expression.Matches(element.Value);
                if (matches.Count == 0)
                {
                    string title   = element.GetAttributeValue("title");
                    string message = string.Empty;
                    if (title != null)
                    {
                        message = string.Format("\r\n{0}", title);
                    }

                    throw new FormElementValidationException(string.Format("Please match the requested format.{0}", message));
                }
            }
        }