$re = '/^
[-−]? #dash or minus
(?: [1-9]\d{0,2}
(?:,\d{3})*
| 0
)
(?:\.\d+)?
$/mx';
$str = 'Valid
0
0.00
0.1
0.01
0.001
0.0001
0.00001
1.0
1
8
9
10
11
12
20
21
99
100
101
111
999
1,000
1,001
2,100
9,999
10,000
999,999
1,000,000
1,000,001
Invalid
00
0,1
0,001
0.0000 1
0,100
9999
,111
999,9999,999';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php