public IEnumerable<ModelClientValidationRule> GetClientValidationRules(
     ModelMetadata metadata,
     ControllerContext context)
 {
     var rule = new ModelClientValidationRegexRule(ErrorMessageString, Pattern);
     return new[] { rule };
 }
Exemplo n.º 2
0
        public static IValidator Regex(string pattern, string errorMessage = null)
        {
            if (String.IsNullOrEmpty(pattern))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "pattern");
            }

            errorMessage = DefaultIfEmpty(errorMessage, WebPageResources.ValidationDefault_Regex);
            var clientAttributes = new ModelClientValidationRegexRule(errorMessage, pattern);
            return new ValidationAttributeAdapter(new RegularExpressionAttribute(pattern), errorMessage, clientAttributes);
        }