RegularExpression Message Error Using Griffin.MvcC

2019-07-30 10:47发布

I'm using Griffin.MvcContrib for metadata message errors validation.

I have Added a custom validation to add a regular expression validation:

protected override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context, IEnumerable<Attribute> attributes) {
    List<ModelValidator> vals = base.GetValidators(metadata, context, attributes).ToList();

    //if (metadata.ModelType.Name == "DateTime")
    if (metadata.DataTypeName == "telephone") {
        DataAnnotationsModelValidationFactory factory;

        RegularExpressionAttribute regex = new RegularExpressionAttribute(@"^(((\+?34([ |\-])?)|(\+?\(34\)([ |\-])?))?[9|6|7]((\d{1}([ |\-])?[0-9]{3})|(\d{2}([ |\-])?[0-9]{2}))([ |\-])?[0-9]{2}([ |\-])?[0-9]{2})$");
        //regex.ErrorMessage = "Invalid date format";
        if (!AttributeFactories.TryGetValue(regex.GetType(), out factory))
            factory = DefaultAttributeFactory;

        vals.Add(factory(metadata, context, regex));
    }

    return vals.AsEnumerable();
}

In the global assax:

    ModelMetadataProviders.Current = new LocalizedModelMetadataProvider(myResouceFile);
    ModelValidatorProviders.Providers.Clear();
    ModelValidatorProviders.Providers.Add(new LocalizedModelValidatorProvider());
    ModelValidatorProviders.Providers.Clear();
    ModelValidatorProviders.Providers.Add(new MovilityMetadataValidatorProvider());

And in the resources i have the next keys

CommonPrompts_RegularExpression         {0} fu  
Phone_RegularExpression                 {0} fa
RegularExpression                       Incorrect Format

But it keeps showing me this message:

El campo [es-ES: Phone] debe coincidir con la expresión regular '^(((+?34([ |-])?)|(+?(34)([ |-])?))?[9|6|7]((\d{1}([ |-])?[0-9]{3})|(\d{2}([ |-])?[0-9]{2}))([ |-])?[0-9]{2}([ |-])?[0-9]{2})$'.

I have also Added the messages:

AgentDto_Phone_RegularExpression                                {0} regular 
AgentCreateEditViewModel_AgentDto_Phone_RegularExpression       {0} regular 

without any luck.

What have I to put in the Resources to change the message?

0条回答
登录 后发表回答