You can make use of Or Composite Validator that comes with Enterprise Library. You can have Not Null Validator and String Length Validator to perform your validation.
Here's a quick sample:
[ConfigurationElementType(typeof(CustomValidatorData))]
public sealed class CustomValidatorClass : Validator
{
public CustomValidatorClass(string template, string tag)
: base(template, tag)
{
}
protected override string DefaultMessageTemplate
{
get { return "blah blah"; }
}
public override void DoValidate(object objectToValidate, object currentTarget, string key, ValidationResults validationResults)
{
//Do something here
}
}
In the configuration file:
<validation>
<type name="ConsoleApplication1.PropertyClass" assemblyName="ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<ruleset name="Validation Ruleset">
<properties>
<property name="MyProperty">
<validator type="ConsoleApplication1.MyClass, ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
messageTemplate="Blah blah" name="MyClass" />
</property>
</properties>
</ruleset>
</type>
</validation>
You can use the generic class for any specific type you want to validate or any of the classes that already extend Validator class in Enterprise Library API.