Regular expression for integers or two decimal places floating point numbers

I want to check my currency field with a regular expression. I want to allow the following pattern entries

1.23
1
.45
0.56
56.00

No comma should be allowed. I tried \d+(\.\d\d), but it only allows the first, fourth and fifth entries. \d+(?:\.\d\d+)?allows you to use everything except the third.

+5
source share
2 answers

\d* \d+, . (^ $), , . , lookahead, , :

^(?=.*\d)\d*(?:\.\d\d)?$
+7

- :

\d*\.?\d+

, :

(\d*\.\d)?\d+

:

\d+|\d*\.\d{2,}

:

\d+|\d*\.\d{2}

, anchor , .

+3

All Articles