Monday, May 26, 2008

Decimal Regular Expression

The following regular expression checks for a number that can contain up to two decimal places.

^\d*(\.\d{1,2})?$

matches:

123
123.1
123.12

not matches:

123.
123.123