I have an input onchange that converts numbers like 05008
to 5,008.00
.
I am considering expanding on this, to allow simple calculations. For example, 45*5
would be converted automatically to 225.00
.
I could use a character white-list ()+/*-0123456789.
, and then pass the result to eval
, I think that these characters are safe to prevent any dangerous injections. That is assuming I use an appropriate try
/catch
, because a syntax error could be created.
Is this an OK white-list, and then pass it to
eval
?Do recommend a revised white-list
Do you recommend a different approach (maybe there is already a function that does this)
I would prefer to keep it lightweight. That is why I like the
eval
/white-list approach. Very little code.
What do you recommend?