php Dollar amount Regular Expression
Posted
by Thildemar
on Stack Overflow
See other posts from Stack Overflow
or by Thildemar
Published on 2010-05-12T21:08:55Z
Indexed on
2010/05/12
21:14 UTC
Read the original article
Hit count: 241
I am have completed javascript validation of a form using Regular Expressions and am now working on redundant verification server-side using PHP.
I have copied this regular expression from my jscript code that finds dollar values, and reformed it to a PHP friendly format:
/\$?((\d{1,3}(,\d{3})*)|(\d+))(\.\d{2})?$/
Specifically:
if (preg_match("/\$?((\d{1,3}(,\d{3})*)|(\d+))(\.\d{2})?$/", $_POST["cost"])){}
While the expression works great in javascript I get :
Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1
when I run it in PHP. Anyone have a clue why this error is coming up?
© Stack Overflow or respective owner