struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Germuska <...@Germuska.com>
Subject Re: Want to reject all-whitespace text input.
Date Sun, 21 Nov 2004 18:45:06 GMT
At 1:33 PM -0500 11/21/04, Erik Weber wrote:
>I think what you want is to leave out the "required" validator, but 
>to use the "minlength" validator with a value of 1. That should 
>allow a blank, but not a String shorter than 1, and whitespace 
>should be left out in the measurement. (I'm not positive as I don't 
>have the source).

I think Erik's right.  In any case, you won't get the mask validator 
to do it, since it only checks non-empty fields:
-------
from o.a.s.validator.FieldChecks:

     public static boolean validateMask(Object bean,
                                        ValidatorAction va, Field field,
                                        ActionMessages errors,
                                        HttpServletRequest request) {

         String mask = field.getVarValue("mask");
         String value = null;
         if (isString(bean)) {
             value = (String) bean;
         } else {
             value = ValidatorUtils.getValueAsString(bean, field.getProperty());
         }

         try {
             if (!GenericValidator.isBlankOrNull(value)
                 && !GenericValidator.matchRegexp(value, mask)) {

                 errors.add(
                     field.getKey(),
                     Resources.getActionMessage(request, va, field));

                 return false;
             } else {
                 return true;
             }
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }
         return true;
     }
-------


--
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction"  -The Ex
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message