如何在php中使用特定的允许子字符串验证用户定义的算术公式字符串
我只需要使用一些允许的子字符串来验证php中的公式字符串。
Numbers are allowed: 0-9,
Arithmetic operators are allowed: +, -, *, /, (, ), %
Constant string should be allowed: QUANTITY, AMOUNT (this string will be replaced with their actual value )
Need to validate formula string:
eg:
Valid strings:
1. "10",
2. "AMOUNT + 10",
3. "10 * (QUANTITY)",
Invalid strings:
1. "10+",
2. "-10",
3. "AMOUNT + * 10",
4. "* AMOUNT + 10",
5. "AMOUNT 10",
6. "AMOUNT10",
7. "10 (QUANTITY)",
8. "any extra string",
In my case i want to calculate the amount with user defined formula using eval php function.
Please help
thanks in advance