Pre-processing a text before it is validated

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Pre-processing a text before it is validated

Nathan Lai
In Tapestry, how can I pre-process the value of a valid field before it
is validated? For instance, I want to filter out all non-alplanumeric
symbols in a string that is supposed to contain only alphanumeric
characters.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Pre-processing a text before it is validated

Gregg D Bolinger
Seems like instead of manipulating the field before it is validated you
should be validating against a regular expression. Less work for you. I
can't remember off the top of my head though if there is a regex validator.
I'll take a look.

Gregg

On 5/10/05, Nathan Lai <[hidden email]> wrote:

>
> In Tapestry, how can I pre-process the value of a valid field before it
> is validated? For instance, I want to filter out all non-alplanumeric
> symbols in a string that is supposed to contain only alphanumeric
> characters.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Pre-processing a text before it is validated

Gregg D Bolinger
Looks like you need to use a PatternValidator:

http://jakarta.apache.org/tapestry/doc/api/org/apache/tapestry/valid/PatternValidator.html

Gregg

On 5/10/05, Gregg D Bolinger <[hidden email]> wrote:

>
> Seems like instead of manipulating the field before it is validated you
> should be validating against a regular expression. Less work for you. I
> can't remember off the top of my head though if there is a regex validator.
> I'll take a look.
>
> Gregg
>
> On 5/10/05, Nathan Lai <[hidden email]> wrote:
> >
> > In Tapestry, how can I pre-process the value of a valid field before it
> > is validated? For instance, I want to filter out all non-alplanumeric
> > symbols in a string that is supposed to contain only alphanumeric
> > characters.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Pre-processing a text before it is validated

Gregg D Bolinger
I just thought though you might be wanting to manually remove characters on
your own for whatever reason, in which case you will need to do something
before the validator handles it. I don't have an answer for that. Sorry.

Gregg

On 5/10/05, Gregg D Bolinger <[hidden email]> wrote:

>
> Looks like you need to use a PatternValidator:
>
>
> http://jakarta.apache.org/tapestry/doc/api/org/apache/tapestry/valid/PatternValidator.html
>
> Gregg
>
> On 5/10/05, Gregg D Bolinger <[hidden email]> wrote:
> >
> > Seems like instead of manipulating the field before it is validated you
> > should be validating against a regular expression. Less work for you. I
> > can't remember off the top of my head though if there is a regex validator.
> > I'll take a look.
> >
> > Gregg
> >
> > On 5/10/05, Nathan Lai < [hidden email]> wrote:
> > >
> > > In Tapestry, how can I pre-process the value of a valid field before
> > > it
> > > is validated? For instance, I want to filter out all non-alplanumeric
> > > symbols in a string that is supposed to contain only alphanumeric
> > > characters.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Pre-processing a text before it is validated

Bryan Lewis
In reply to this post by Nathan Lai
The standard way is to write your own validator that does your processing
before calling the standard validator's method.  Here's a simple one I wrote
recently to allow dollar signs and commas in the user's input.

/**
 *  Provides input validation for strings treated as numbers.  Derived from
 *  NumberValidator.  Trims the input string and ignores dollar signs and
 *  commas.
 */
public class DollarValidator extends
org.apache.tapestry.valid.NumberValidator
{
    public Object toObject(IFormComponent field, String value) throws
ValidatorException
    {
        if (value != null) {
            // trim() returns a copy of the string as desired.
            value = value.trim();

            // Strip out the dollar signs and commas.
            List pieces = CString.componentsSeparatedByDelimiters(value,
"$,");
            value = CString.componentsJoinedByString(pieces, "");
        }

        return super.toObject(field, value);
    }
}


----- Original Message -----
From: "Nathan Lai" <[hidden email]>
To: "Tapestry users" <[hidden email]>
Sent: Tuesday, May 10, 2005 11:37 AM
Subject: Pre-processing a text before it is validated


> In Tapestry, how can I pre-process the value of a valid field before it
> is validated? For instance, I want to filter out all non-alplanumeric
> symbols in a string that is supposed to contain only alphanumeric
> characters.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]