Example #1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            // Get the error message for this property in the current language
            ErrorMessage = ValidationErrorMsg.GetErrorMessage(path, fieldName, ErrorMessage);

            // use the base IsValid property to do the work
            return(base.IsValid(value, validationContext));
        }
Example #2
0
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var modelClientValidationRule = new ModelClientValidationRule
            {
                ValidationType = "sitecorerequiredfield",
                ErrorMessage   = ValidationErrorMsg.GetErrorMessage(path, fieldName, ErrorMessage)
            };

            modelClientValidationRule.ValidationParameters.Add("param", metadata.PropertyName);
            return(new List <ModelClientValidationRule> {
                modelClientValidationRule
            });
        }
Example #3
0
        public override bool IsValid(object value)
        {
            string input = value == null ? string.Empty : value.ToString();
            bool   valid = true;
            Regex  regex = new Regex(@pattern);

            if (!String.IsNullOrEmpty(input))
            {
                Match match = regex.Match(input);
                if (!match.Success)
                {
                    valid        = false;
                    ErrorMessage = ValidationErrorMsg.GetErrorMessage(path, fieldName, ErrorMessage);
                }
            }

            // use the base IsValid property to do the work
            return(valid);
        }