问题
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?
来源:https://stackoverflow.com/questions/23105025/regularexpression-message-error-using-griffin-mvccontrib