如何在Javascript中验证代数表达式 [英] How Do I Validate Algebraic Expression In Javascript
本文介绍了如何在Javascript中验证代数表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是javascript中正则表达式验证的新手。
我的文本框允许用户输入需要验证客户端的FORMULA。
我的公式可以由以下运营商组成
+
_
*
/
(
)
%
这些是我文本框中允许的唯一符号。
需要验证公式
wchic应该像CurrentbaseSalary + CurrentMBP(BPI)
但不应该是+ BPI-CBI(
应该是一个有效的公式。
请帮助。
提前致谢。
I'm new to Regular expression validations in javascript.
My textbox allows the user to enter FORMULA which needS to be validated client side.
My Formula Can be made of following operators
+
_
*
/
(
)
%
these are the only symbols allowed in my textbox.
need to validate a formula
wchic should be like "CurrentbaseSalary+CurrentMBP(BPI)"
but should not be "+BPI-CBI("
should be a valid formula.
please help.
Thanks in advance.
推荐答案
如果评估 [ ^ ]功能不适合您的需求 Google for Javascript表达式解析器 [ ^ ]。
If the eval[^] function doesn't fit your needs you might Google for a Javascript expression parser[^].
我强烈建议您阅读:JavaScript Calculator [ ^ ]
I do strongly recommend you to read this: JavaScript Calculator[^]
这篇关于如何在Javascript中验证代数表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文