You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Morten Hoey <Mo...@TietoEnator.com> on 2002/09/09 15:12:09 UTC

Formattet number validator

Hi!

I have been trying to set up a validation rule for handling formatted
numbers and ended up with the definition below.

The pattern handles formats like:

2500
-2500
2500.00
-2500.00
2,500.00
-2,500.00

To extend it with a currency indicator e.g $ add \$? in both sub patterns

Unfortunately you can't convert the formatted number directly to float,
double, because of the commas. So you can either remove the commas or use
the DecimalFormat class with a pattern like: #,###,###,###,##0 in the action
class.

I have only tested it on Struts1.1b2 on a websphere, so no garanties given
:)

Regards 
  Morten

<form-validation>
   <global>
      <constant>
        <constant-name>currency</constant-name>
 
<constant-value>(^\-?\d{1,3}(\,{1}\d{3})*\.{1}\d{2}$)|(^\-?\d+(\.\d{2})?$)</
constant-value>
      </constant>
   </global>
   <formset>
      <form    name="herc1">
         <field property="quantity"
         	depends="required,mask">
         	     <arg0 key="herc1.quantity.displayname"/>
                     <var>
                      <var-name>mask</var-name>
                      <var-value>${currency}</var-value>
                     </var>
         </field>
      </form>
   </formset>
</form-validation>

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


Re: Validation documentation (help requested)

Posted by Craig Tataryn <cr...@hotmail.com>.
Here you go:

http://home.earthlink.net/~dwinterfeldt/index.html

Craig.
----- Original Message -----
From: "Carlos Saraiva" <ja...@carlossaraiva.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Monday, September 09, 2002 10:10 AM
Subject: Validation documentation (help requested)


> Hello,
>
> I'm a new Struts user, and would like some pointers to documentation,
> especially for validation. I figured out how to install and use the
> framework, and actually have a small app up and running, but I'm have a
> terrible time getting started on validation.
>
> Best regards,
> Carlos Saraiva
> Raleigh, NC
> http://www.carlossaraiva.com
> mailto:saraiva@pobox.com
>
>
>
> --
> 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>


RE: Validation documentation (help requested)

Posted by Carlos Saraiva <ja...@carlossaraiva.com>.
> Eddie:
> 1) Go to http://www.theserverside.com/
> 2) Search for "struts book review"
> 3) Download and read all the sample chapters
> 4) Go pre-order your own copy on bookpool.com

Thanks Eddie, I've downloaded the chapters, and will buy the book as soon as
it's published.

Best regards,
Carlos Saraiva
Raleigh, NC
http://www.carlossaraiva.com
mailto:saraiva@pobox.com



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


Re: Validation documentation (help requested)

Posted by Eddie Bush <ek...@swbell.net>.
1) Go to http://www.theserverside.com/
2) Search for "struts book review"
3) Download and read all the sample chapters
4) Go pre-order your own copy on bookpool.com

Chuck does a good job at introducing Struts to newcomers.  That should 
give you a really good jump-start.

Regards,

Eddie

Carlos Saraiva wrote:

>Hello,
>
>I'm a new Struts user, and would like some pointers to documentation,
>especially for validation. I figured out how to install and use the
>framework, and actually have a small app up and running, but I'm have a
>terrible time getting started on validation.
>
>Best regards,
>Carlos Saraiva
>Raleigh, NC
>http://www.carlossaraiva.com
>mailto:saraiva@pobox.com
>
>
>
>--
>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>


Validation documentation (help requested)

Posted by Carlos Saraiva <ja...@carlossaraiva.com>.
Hello,

I'm a new Struts user, and would like some pointers to documentation,
especially for validation. I figured out how to install and use the
framework, and actually have a small app up and running, but I'm have a
terrible time getting started on validation.

Best regards,
Carlos Saraiva
Raleigh, NC
http://www.carlossaraiva.com
mailto:saraiva@pobox.com



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