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 string DefaultErrorMessage { get; set; }

        public SitecoreRequiredField(string fieldName)
        {
            // The path is the GUID of the item that holds the validation messages
            this.path = ValidationErrorMsg.GetPath();

            // The fieldname is the name of the Sitecore field on the "path" item that relates
            // to this property
            this.fieldName = fieldName;
        }
Example #3
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 #4
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);
        }
Example #5
0
 public SitecoreRegEx(string fieldName, string RegExpattern)
 {
     this.fieldName = fieldName;
     this.path      = ValidationErrorMsg.GetPath();
     this.pattern   = RegExpattern;
 }