예제 #1
0
        /// <summary>
        /// Converts the given validity state to a validation error enum.
        /// </summary>
        protected static ValidationErrors GetErrorsFrom(IValidityState state)
        {
            var result = ValidationErrors.None;

            if (state.IsBadInput)
            {
                result ^= ValidationErrors.BadInput;
            }

            if (state.IsTooShort)
            {
                result ^= ValidationErrors.TooShort;
            }

            if (state.IsTooLong)
            {
                result ^= ValidationErrors.TooLong;
            }

            if (state.IsValueMissing)
            {
                result ^= ValidationErrors.ValueMissing;
            }

            if (state.IsCustomError)
            {
                result ^= ValidationErrors.Custom;
            }

            return(result);
        }
예제 #2
0
        public override ValidationErrors Check(IValidityState current)
        {
            var value = Input.Value;
            var date  = ConvertFromDate(value);
            var min   = ConvertFromDate(Input.Minimum);
            var max   = ConvertFromDate(Input.Maximum);

            return(CheckTime(current, value, date, min, max));
        }
예제 #3
0
        public override ValidationErrors Check(IValidityState current)
        {
            var result = GetErrorsFrom(current);

            if (IsInvalidPattern(Input.Pattern, Input.Value ?? String.Empty))
            {
                result ^= ValidationErrors.PatternMismatch;
            }

            return(result);
        }
예제 #4
0
        public override ValidationErrors Check(IValidityState current)
        {
            var result = GetErrorsFrom(current);

            result &= ~ValidationErrors.ValueMissing;

            if (Input.IsRequired && !Input.IsChecked)
            {
                result ^= ValidationErrors.ValueMissing;
            }

            return(result);
        }
예제 #5
0
        public override ValidationErrors Check(IValidityState current)
        {
            var value  = Input.Value ?? String.Empty;
            var result = GetErrorsFrom(current);

            if (IsInvalidPattern(Input.Pattern, value))
            {
                result ^= ValidationErrors.PatternMismatch;
            }

            if (IsInvalidUrl(value) && !String.IsNullOrEmpty(value))
            {
                result ^= ValidationErrors.TypeMismatch | ValidationErrors.BadInput;
            }

            return(result);
        }
예제 #6
0
        public override ValidationErrors Check(IValidityState current)
        {
            var result = GetErrorsFrom(current);

            if (!color.IsMatch(Input.Value ?? String.Empty))
            {
                result ^= ValidationErrors.BadInput;

                if (Input.IsRequired)
                {
                    result ^= ValidationErrors.ValueMissing;
                }

                return(result);
            }

            return(ValidationErrors.None);
        }
예제 #7
0
        /// <summary>
        /// Validates the time using the given parameters.
        /// </summary>
        protected ValidationErrors CheckTime(IValidityState state, String value, DateTime?date, DateTime?min, DateTime?max)
        {
            var result = state.IsCustomError ?
                         ValidationErrors.Custom :
                         ValidationErrors.None;

            if (date.HasValue)
            {
                if (min.HasValue && date < min.Value)
                {
                    result ^= ValidationErrors.RangeUnderflow;
                }

                if (max.HasValue && date > max.Value)
                {
                    result ^= ValidationErrors.RangeOverflow;
                }

                if (IsStepMismatch())
                {
                    result ^= ValidationErrors.StepMismatch;
                }
            }
            else
            {
                if (Input.IsRequired)
                {
                    result ^= ValidationErrors.ValueMissing;
                }

                if (!String.IsNullOrEmpty(value))
                {
                    result ^= ValidationErrors.BadInput;
                }
            }

            return(result);
        }
예제 #8
0
        public override ValidationErrors Check(IValidityState current)
        {
            var value  = Input.Value;
            var num    = ConvertToNumber(value);
            var result = current.IsCustomError ?
                         ValidationErrors.Custom :
                         ValidationErrors.None;

            if (num.HasValue)
            {
                var min = ConvertToNumber(Input.Minimum);
                var max = ConvertToNumber(Input.Maximum);

                if (min.HasValue && num < min.Value)
                {
                    result ^= ValidationErrors.RangeUnderflow;
                }

                if (max.HasValue && num > max.Value)
                {
                    result ^= ValidationErrors.RangeOverflow;
                }

                if (IsStepMismatch())
                {
                    result ^= ValidationErrors.StepMismatch;
                }
            }
            else
            {
                if (Input.IsRequired)
                {
                    result ^= ValidationErrors.ValueMissing;
                }
            }

            return(result);
        }
예제 #9
0
 /// <summary>
 /// Checks the current input for its validity.
 /// </summary>
 public virtual ValidationErrors Check(IValidityState current)
 {
     return(GetErrorsFrom(current));
 }
예제 #10
0
 /// <summary>
 /// Checks the form control for validity.
 /// </summary>
 /// <param name="state">The element's validity state tracker.</param>
 protected override void Check(IValidityState state)
 {
     //TODO
 }