I am trying to write simple calculator with JavaScript. I want to check if user input is correct or not. I wrote regular expression in order to make sure user input is prope
^[-+]?
Is correct, but then
[0-9]{0,}
Is not, you want + quantifier as if you use {0,} (which is the same as *) you could have "+*9" being correct. Then,
([-+*/]?)[0-9]+
Is wrong, you want :
([-+*/]+[-+]?[0-9]+)*
So you will have for instance *-523+4234/-34 (you can use an operand on an either negative or positive number, or not precised number which would mean obviously positive)
So finally, you would have something like :
^[-+]?[0-9]+([-+*/]+[-+]?[0-9]+)*$
Of course, you can replace class [0-9] with \d