You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Roland G." <ro...@gisplan.com.br> on 2005/03/23 22:35:28 UTC

Problem: Validator not validating whitespace fields

Hello,

I searched the mailing lists archives but didn't find anything related 
to this problem.

I noticed the following behaviour when validating a field:
When the form field is empty or contains only whitespace, it isn't 
validated.

Basically what happens is that when the field has only whitespace the 
validator considers it as empty and doesn't run it through the 
validation routines. I'm using the "mask" validator here.

This causes problems:

I have some fields that are optional. But if they are not empty, they 
should conform to certain REGEXP patterns. Now, if the field has only 
whitespace in it, it isn't rejected by the validator and the action 
receives a String that is neither empty nor conforms to the REGEXP.

My workaround: In all fields where this happens I call String.trim() 
first, to get rid of the whitespace and then check if the String is empty.

Is this a bug?

Thanks for any feedback,

Roland

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org