You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Wendy Smoak <We...@asu.edu> on 2003/04/04 17:16:19 UTC

[VALIDATOR] Validating formatted amounts

I have an 'amount' field (text box) on a Struts form, and I need to validate
it.  I'm having some success with:

<field    property="askAmount"
           depends="required,integer,intRange">

but I know my users will want to enter 5,000 or $5,000 or 5000.00 instead of
just 5000.

Suggestions please?  I didn't get any answers from struts-user, so I'm
thinking I need to write a custom validator for this.  

-- 
Wendy Smoak
Applications Systems Analyst, Sr.
Arizona State University PA Information Resources Management

Re: [VALIDATOR] Validating formatted amounts

Posted by Erik Price <ep...@ptc.com>.

Dave Newton wrote:
> On Fri, 2003-04-04 at 10:16, Wendy Smoak wrote:
> 
>>but I know my users will want to enter 5,000 or $5,000 or 5000.00 instead of
>>just 5000.
> 
> 
> Worse, if it's an I18N app; using "," for the decimal point for example.
> 
> 
>>Suggestions please?  I didn't get any answers from struts-user, so I'm
>>thinking I need to write a custom validator for this.  
> 
> 
> I'd poke around for currency validators in any language (preferably
> java, of course) and wrap it up in a custom just like you are already
> thinking.

Yes, and also there must be dozens of JavaScript currency validators and 
you can just use one of these in your JSP/output -- set an onBlur event 
handler to change it to the "neutral" form if the user tabs or clicks 
outside the field.  This will notify your users that they can just enter 
5000 instead of all the extra jazz.

So as not to rely exclusively on JavaScript, which can be disabled, in 
your CustomValidator implementation you might want to consider using 
NumberFormat.getCurrencyInstance() and parsing the string with that....


Erik


Re: [VALIDATOR] Validating formatted amounts

Posted by Dave Newton <da...@solaraccess.com>.
On Fri, 2003-04-04 at 10:16, Wendy Smoak wrote:
> but I know my users will want to enter 5,000 or $5,000 or 5000.00 instead of
> just 5000.

Worse, if it's an I18N app; using "," for the decimal point for example.

> Suggestions please?  I didn't get any answers from struts-user, so I'm
> thinking I need to write a custom validator for this.  

I'd poke around for currency validators in any language (preferably
java, of course) and wrap it up in a custom just like you are already
thinking.

Dave