Thursday 12 September 2013

php preg_match mathematical expresion

php preg_match mathematical expresion

I wanna make a check before php eval(string), so I wonder how should i
check if string is correct mathematical expression?
Need:
preg_match for 0123456789 + - * / ( )
and should start with ( or number
It shouldnt accept incorrect math expression like (1+1)+)
edit: I've tryed both
^([-+/*]\d+(\.\d+)?)*^
and
/[^0-9\+\-\*\/\(\)\.]/
but these doesnt catch incorrect math.

No comments:

Post a Comment