PHP regular expression for positive number with 0 or 2 decimal places

Posted by Peter on Stack Overflow See other posts from Stack Overflow or by Peter
Published on 2010-06-12T06:33:53Z Indexed on 2010/06/12 6:42 UTC
Read the original article Hit count: 273

Filed under:
|
|

Hi

I am trying to use the following regular expression to check whether a string is a positive number with either zero decimal places, or 2:

^\d+(\.(\d{2}))?$

When I try to match this using preg_match, I get the error:

Warning: preg_match(): No ending delimiter '^' found in /Library/WebServer/Documents/lib/forms.php on line 862

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about php

Related posts about regex