Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public override string FormatErrorMessage(string name)
        {
            //Get dictionary value for thge required error message
            //WB: UNSURE if this will double check our UmbContext exists or not
            ErrorMessage = UmbracoValidationHelper.FormatErrorMessage(name, ErrorMessageDictionaryKey, DefaultText);

            return(base.FormatErrorMessage(name));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            ErrorMessage = UmbracoValidationHelper.GetDictionaryItem(_errorMessageDictionaryKey, _defaultText);

            var error = UmbracoValidationHelper.FormatErrorMessage(metadata.DisplayName, _errorMessageDictionaryKey, _defaultText);;
            var rule  = new ModelClientValidationRequiredRule(error);

            yield return(rule);
        }
Beispiel #3
0
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var error = UmbracoValidationHelper.FormatErrorMessage(metadata.DisplayName, ErrorMessageDictionaryKey, DefaultText);
            var rule  = new ModelClientValidationRule
            {
                ErrorMessage   = error,
                ValidationType = "email"
            };

            yield return(rule);
        }
Beispiel #4
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            //Convert the value to a bool & check it's true
            if ((bool)value)
            {
                //All good :)
                return(ValidationResult.Success);
            }

            //Get the error message to return
            var error = UmbracoValidationHelper.FormatErrorMessage(validationContext.DisplayName, ErrorMessageDictionaryKey);

            //Return error
            return(new ValidationResult(error));
        }
Beispiel #5
0
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            ErrorMessage = UmbracoValidationHelper.GetDictionaryItem(_errorMessageDictionaryKey, _defaultText);

            var error = UmbracoValidationHelper.FormatErrorMessage(metadata.DisplayName, _errorMessageDictionaryKey, _defaultText);
            var rule  = new ModelClientValidationRule
            {
                ErrorMessage   = error,
                ValidationType = "regex"
            };

            rule.ValidationParameters.Add("pattern", Pattern);

            yield return(rule);
        }
Beispiel #6
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var email = Convert.ToString(value);

            if (!string.IsNullOrEmpty(email))
            {
                //Test the regex
                var result = _regex.Match(email).Length > 0;

                //If no matches then email NOT valid
                if (!result)
                {
                    //Get the error message to return
                    var error = UmbracoValidationHelper.FormatErrorMessage(validationContext.DisplayName, ErrorMessageDictionaryKey, DefaultText);

                    //Return error
                    return(new ValidationResult(error));
                }
            }

            //All good :)
            return(ValidationResult.Success);
        }