Ejemplo n.º 1
0
        public object Validate(string value, ValidationContext context) {
            // ignore the value - we actually need to look at the DOM Elements

            DOMElement[] elements = context.FieldContext.Elements;
            if (elements.Length == 0) {
                // nothing to validate, so return success
                return true;
            }

            DOMElement sampleElement = elements[0];
            if (IsTextualInputElement(sampleElement)) {
                return ValidateTextualInput((InputElement)sampleElement);
            }

            if (IsRadioInputElement(sampleElement)) {
                return ValidateRadioInput(elements);
            }

            if (IsSelectInputElement(sampleElement)) {
                return ValidateSelectInput(((SelectElement)sampleElement).Options);
            }

            // can't validate, so just report success
            return true;
        }
        public object Validate(string value, ValidationContext context) {
            if (ValidationUtil.StringIsNullOrEmpty(value)) {
                return true; // let the RequiredValidator handle this case
            }

            return (_minLength <= value.Length && value.Length <= _maxLength);
        }
Ejemplo n.º 3
0
        public object Validate(string value, ValidationContext context) {
            if (ValidationUtil.StringIsNullOrEmpty(value)) {
                return true; // let the RequiredValidator handle this case
            }

            Number n = Number.ParseLocale(value);
            return (!Number.IsNaN(n) && _minimum <= n && n <= _maximum);
        }
        public object Validate(string value, ValidationContext context) {
            if (ValidationUtil.StringIsNullOrEmpty(value)) {
                return true; // let the RequiredValidator handle this case
            }

            RegularExpression regExp = new RegularExpression(_pattern);
            string[] matches = regExp.Exec(value);
            return (!ValidationUtil.ArrayIsNullOrEmpty(matches) && matches[0].Length == value.Length);
        }
Ejemplo n.º 5
0
        public string[] Validate(string eventName) {
            Validation[] validations = Validations;
            ArrayList errors = new ArrayList();
            string value = GetStringValue();

            // build up the list of all errors
            for (int i = 0; i < validations.Length; i++) {
                Validation validation = validations[i];
                ValidationContext context = new ValidationContext();
                context.EventName = eventName;
                context.FieldContext = this;
                context.Validation = validation;

                object retVal = validation.Validator(value, context);

                string errorMessage = GetErrorString(retVal, validation.FieldErrorMessage);
                if (!ValidationUtil.StringIsNullOrEmpty(errorMessage)) {
                    ArrayList.Add(errors, errorMessage);
                }
            }

            MarkValidationFired();
            ClearErrors();
            AddErrors((string[])errors);
            return (string[])errors;
        }