string validation question

Hi everyone

I’m having the following issue:

I would like to validate the length of a string. Validation should fail if the attribute has been set and the string is empty. I had to set allowEmpty => false for it to do that.

However, I also want validation to pass if the attribute is not present at all (if it wasn’t included in the form).

I figured that CStringValidator would let this pass since checking for the presence of an attribute should really be left up to the required validator.

Is there any way to do what I wanna do without writing a custom validator?


Did you think about scenario?

yes but in my case it’s not really feasible.

I think of it more as a general issue though.

Since the required validator can take care of checking the presence of an attribute, why would the other validators do the same?

This requirement is actually rarely needed in reality. If you are using a text field to collect input for the attribute, then no matter user enters anything or not, the form will be posted back with that field.

Because this is so rare, you may consider writing a custom validation method to achieve this.