On 4/6/06, Dr.Ruud <[EMAIL PROTECTED]> wrote:
> Owen schreef:
> > I would like to accept monetary values like
> >
> > $234.00
> > $2678
> >
> > but not values with letters like
> >
> > $333.oo
> >
> > This script below almost works, but I can't get it to catch the
> > $40o.89
> >
> > Is there a simpler way to do this and catch all the conditions?
>
> See Regexp::Common::number
>   http://search.cpan.org/~abigail/Regexp-Common/
>
> http://search.cpan.org/~abigail/Regexp-Common/lib/Regexp/Common/number.pm
>

Regexp::Common is a godsend for this sort of thing, absolutely! The
problem is still complicated, though. OP hasn't said what this will be
used for, but number formats are vry locale specific, particularly
currency formats. '$###,###.##' isn't the only way to represent a
dollar amount, and if this is going to be used for any sort of
external audience, you'll want to be prepred for a variety of input.
For the amount "one thousand U.S. Dollars," the following are all
popular representations:

$1,000.00
$1000.00
$1000
USD\s?1000
USD\s?1000.00
1000 USD
1000.00 USD
USD\s?1000,00
USD\s?1.000,00
USD\s?1 000,00
$1.000,00
$1 000,00
1.000,00
1 000,00

Which of the options you can expect to get as input will depend on the
context in which the question is asked, and where your users are
physically. This is a particular nuissance for web designers.

HTH

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to