Here's a better mask to use: 
<var>
    <var-name>mask</var-name>
    <var-value>^\$?\d+(,\d{3})*(\.\d{2})?$</var-value>
</var>

This mask: 
--allows (but does not require) a leading dollar sign (if you want to remove
this feature, get rid of the "\$?" at the beginning (but leave the "^")
--allows (but does not require) a decimal point + 2 trailing digits.  

It requires:
--each comma to have at least 1 digit before it (fails on ",500") 
--exactly three digits after each comma (fails on "$1,00.00")

Here's a tester you can put in your HTML:
<script>
 var pattern = /^\$?\d+(,\d{3})*(\.\d{2})?$/;
 if (pattern.exec("$1,500,200.99")) {
    alert ('matches');
  } else {
    alert ('does not match');
  }
</script> 

HTH,
Greg

-----Original Message-----
From: Hubert Rabago [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 06, 2005 3:39 PM
To: Struts Users Mailing List
Subject: Re: Validating an amount with commas allowed

I'm useless with regex.  However, I found this on the web some time ago and
seemed to match what I needed back then:

<var>
    <var-name>mask</var-name>
    <var-value>^(?:\d+|\d{1,3}(?:,\d{3})*)(?:\.\d{1,2}){0,1}$</var-value>
</var>

This allows them to include the ".00" if they so desire.

hth,
Hubert

On Apr 6, 2005 5:08 PM, Wendy Smoak <[EMAIL PROTECTED]> wrote:
> I have a form with a required "amount".  The users like to enter 
> things like $50k which thoroughly confuses the system that tries to 
> send a different email if the amount is over or under $25,000.  I 
> think I can make them stop entering dollar signs and letters... but I 
> don't think they'll part with the commas.
> 
> Before I write a custom validator, am I missing something simple that 
> would allow me to accept "40,000" as a valid amount?  The only thing I 
> see is integer validation, which is too strict.
> 
> Thanks,
> --
> Wendy Smoak
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to