How to Create Custom Validators with EL4.1?

Topics: Building and extending application blocks, Validation Application Block
Jul 29, 2009 at 8:59 PM


I want to create a set of custom validators for my project.  The will be used explicitly for attribute based validation.   I need to be able to provide MessageTemplate from my application's RESX file.  I am using EL4.1

Something like this:


[StringLengthValidator(0, RangeBoundaryType.Inclusive,
          500, RangeBoundaryType.Inclusive,
          MessageTemplateResourceName = INF.Shared.Constants.MessageTemplateResourceName.InvalidStringLength,
          MessageTemplateResourceType = typeof(INF.Shared.Resources.SystemMessageTemplate),
          Ruleset = INF.Shared.Constants.RuleSetName.InsertUpdate)]

[MyCustomStringLengthValidator(0, RangeBoundaryType.Inclusive,

          500, RangeBoundaryType.Inclusive,

          MessageTemplateResourceName = Constants.MessageTemplateResourceName.InvalidStringLength,

          MessageTemplateResourceType = typeof(Resources.SystemMessageTemplate),

          Ruleset = Constants.RuleSetName.InsertUpdate)]




How can I accomplish this easily.   Is there a quick sample anyone has?

I need this help quickly. 


Thanks in advance for any guidance you can provide.

Jul 30, 2009 at 9:04 AM


There are some samples you can find in the Validation quick starts, you can find it in the installation folder of the Ent lib source, usually <Drive Letter>:\EntLib41Src\Quick Starts. Basically the sample has a class for the attribute validation and for the validation using the config. I just tried it and is working fine. Just follow the pattern on how that classes were created.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.


Jul 30, 2009 at 2:29 PM

Found them!  perfect.  we are using attribute and not config based validation...


Just got our first CustomeSample validator done.