Is using javascript eval() safe for simple calculations in inputs?

前端 未结 2 1486
故里飘歌
故里飘歌 2020-12-06 17:16

I would like to allow user to perform simple calculations in the text inputs, so that typing 2*5 will result in 10. I\'m replacing everything but digits with an empty string

2条回答
  •  春和景丽
    2020-12-06 18:02

    this is safe because you are doing input validation before you put it into eval.

    besides you should also add:

    ()%

提交回复
热议问题