예제 #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
        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));
                }
            }
        }