Regular Expression question..simple!

Hey everyone! I am banging my head on this regular expression problem.
I want to validate US currency. So far I have '^(\.[0-9]+|[0-9]+(\.
[0-9]*)?)$'

but this fails if I use a commna (i.e. 2,000.00). Any help would be
greatly appreciated!
gene.ellis [ Di, 30 Januar 2007 22:19 ] [ ID #1613103 ]

Re: Regular Expression question..simple!

On Jan 30, 11:19 pm, "gene.el... [at] gmail.com" <gene.el... [at] gmail.com>
wrote:
> Hey everyone! I am banging my head on this regular expression problem.
> I want to validate US currency. So far I have '^(\.[0-9]+|[0-9]+(\.
> [0-9]*)?)$'
>
> but this fails if I use a commna (i.e. 2,000.00). Any help would be
> greatly appreciated!

Use '^(\.[0-9]+|[0-9,]+(\.[0-9]*)?)$' - this will also accept
2,0,0,0.00
Or use ^(([0-9]{1,3},)*[0-9]{1,3}|[0-9]+)(\.[0-9]+)?$'
AlexVN [ Mi, 31 Januar 2007 00:31 ] [ ID #1613105 ]

Re: Regular Expression question..simple!

gene.ellis [at] gmail.com wrote:
> Hey everyone! I am banging my head on this regular expression problem.
> I want to validate US currency. So far I have '^(\.[0-9]+|[0-9]+(\.
> [0-9]*)?)$'
>
> but this fails if I use a commna (i.e. 2,000.00). Any help would be
> greatly appreciated!
>

One way to deal with it is to strip out any commas first.
You probably don't want them anyway.
Preventer of Work [ Mi, 31 Januar 2007 01:00 ] [ ID #1613107 ]
PHP » alt.php » Regular Expression question..simple!

Vorheriges Thema: php.ini for every vhost
Nächstes Thema: Date comparison issue