I have a DateTime TemplateEditor and I would like to add regex validation to it. I have a RegularExpression attribute that I could decorate the model with, but I dont want to have to decorate every datetime property in all my models with a regex.
Is there way I can my custom TemplateEditor add the appropriate unobstrusive tags when it renders the textbox for it?
Instead of adding your validator in the template, you should insert your validator using a custom
ModelMetadataValidatorProvider. First, create your ModelMetadataProvider class:Next, register your ModelMetadataValidatorProvider in
Global.asax.csinApplication_Start.Now, when you access a model, a RegularExpressionAttribte will be attached to each DateTime field. You can also extend this to provide a localized DateTime regular expression and message.
counsellorben