You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Halvorson, Loren" <Lo...@firepond.com> on 2002/10/28 18:45:44 UTC

Can validator mask rule be made optional

Currently we are using the validator-rules.xml that comes with the Struts
1.1 distribution.  We have several situations where we have fields we need
to conform to a pattern _if_ the user enters data, but the fields are not
required (ex: phone number, e-mail).  We noticed that the mask validation
rule and the email validation rule depend on "required".  Is there an easy
way to accomplish making these optional (short of duplicating the entire
rule and making an "optionalMask" by removing the "required"
dependency...which is what we are doing now)

<validator name="mask"
  classname="org.apache.struts.validator.FieldChecks"
  method="validateMask"
  methodParams="java.lang.Object,
    org.apache.commons.validator.ValidatorAction,
    org.apache.commons.validator.Field,
    org.apache.struts.action.ActionErrors,
    javax.servlet.http.HttpServletRequest"
  depends="required"  <<<-------REMOVE THIS REQUIRED
  msg="errors.invalid">
  <javascript>...</javascript>
</validator>

A thought just occurred to me as I was typing this. I suppose we could
rewrite the regular expression to accept empty string _or_ a valid phone
pattern...duh.  I suppose this is the preferred way to accomplish this.
Here is the pattern we are using today:

<form-validation>
    <global>
      <constant>
        <constant-name>phone</constant-name>
        <constant-value>^\(?(\d{3})\)?[-| ]?(\d{3})[-|
]?(\d{4})$</constant-value>
      </constant>
    </global>
</form-validation>

I may be able to get this to work for the "mask" rule, but it doesn't solve
the email rule which doesn't use an exernally specified regular expression.
Does anyone else have a form with an optional e-mail?

Thanks

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Can validator mask rule be made optional

Posted by Dan Tran <da...@hotmail.com>.
The nightly build on 10/25 solves this problem

or you can just edit validation-rules.xml and
remove the "required" dependency

-Dan
----- Original Message -----
From: "Halvorson, Loren" <Lo...@firepond.com>
To: <st...@jakarta.apache.org>
Sent: Monday, October 28, 2002 9:45 AM
Subject: Can validator mask rule be made optional


> Currently we are using the validator-rules.xml that comes with the Struts
> 1.1 distribution.  We have several situations where we have fields we need
> to conform to a pattern _if_ the user enters data, but the fields are not
> required (ex: phone number, e-mail).  We noticed that the mask validation
> rule and the email validation rule depend on "required".  Is there an easy
> way to accomplish making these optional (short of duplicating the entire
> rule and making an "optionalMask" by removing the "required"
> dependency...which is what we are doing now)
>
> <validator name="mask"
>   classname="org.apache.struts.validator.FieldChecks"
>   method="validateMask"
>   methodParams="java.lang.Object,
>     org.apache.commons.validator.ValidatorAction,
>     org.apache.commons.validator.Field,
>     org.apache.struts.action.ActionErrors,
>     javax.servlet.http.HttpServletRequest"
>   depends="required"  <<<-------REMOVE THIS REQUIRED
>   msg="errors.invalid">
>   <javascript>...</javascript>
> </validator>
>
> A thought just occurred to me as I was typing this. I suppose we could
> rewrite the regular expression to accept empty string _or_ a valid phone
> pattern...duh.  I suppose this is the preferred way to accomplish this.
> Here is the pattern we are using today:
>
> <form-validation>
>     <global>
>       <constant>
>         <constant-name>phone</constant-name>
>         <constant-value>^\(?(\d{3})\)?[-| ]?(\d{3})[-|
> ]?(\d{4})$</constant-value>
>       </constant>
>     </global>
> </form-validation>
>
> I may be able to get this to work for the "mask" rule, but it doesn't
solve
> the email rule which doesn't use an exernally specified regular
expression.
> Does anyone else have a form with an optional e-mail?
>
> Thanks
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>