Juan Carlos Rodriguez
Juan Carlos Rodriguez

Reputation: 784

Microsoft StringLenghtValidator validating an empty string

I'm trying to validate a string so it has a max lenght of 2 using StringLenghtValidator. When the app starts the string is empty but it still gets validated due to architecture.

<validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      upperBoundType="Exclusive" upperBound="3" messageTemplate="Length doesn't fit the needs" tag="Critical" name="appearer_stringlengthvalidator" />

When the string is empty it show the validation message too. I've tried with lowerBound="0" and lowerBoundType="Ignore" but it seems it doesn't work with empty strings.

How could I ignore that validation while the string is empty ?

Upvotes: 1

Views: 71

Answers (1)

Juan Carlos Rodriguez
Juan Carlos Rodriguez

Reputation: 784

After a few days looking for the answer I have just realized what's happening... The value that comes from the database is null, not empty. Even when I set the VM to empty due to the architecture it sets a null value.

Seems like StringLengthValidator doesn't accept a null value and raise the error.

Upvotes: 1

Related Questions