cdub cdub - 6 months ago 28
PHP Question

PHP Regular Expression for currency

I am curious about finding a regular expression for dollars. My inputs and rules are that there can only be digits 0 to 9 and an optional deciaml point. If the decimal exists, it must have two 0 t 9 digits after it.

So it can except:
1000
1000.99

But not:
10001.1
1000.
1,000
$100.9

Answer

Here you go:

/^[0-9]+(?:\.[0-9]{2}){0,1}$/