How can I validate some string if this is the rule:
- can be empty
- if not empty -> max length: 30
I know this two ways:
[IgnoreNulls]
[StringLengthValidator(30)]
or
[ValidatorComposition(CompositionType.Or)]
[StringLengthValidator(30)]
[NotNullValidator(Negated=true)]
but is there a way NOT to use IgnoreNulls or Composition.Or (have problems: Entlib5 Validation [IgnoreNull] throws exception while adding objects to list)
I’ve solved this issue. I couldn’t use Composition, NotNull or IgnoreNull validators. What I did is:
Now, in first call field _address is not null, it’s empty string and IgnoreNulls annotation is now not needed. StringLengthValidator now checks only if Address is <=30 characters.