Checking an input string

I do math applications for the web. Often I have to check if a user input is correct. For example: the right answer is 3x+5. Is the user input that.

I do this by checking character by character. I don’t think that it is the best way, especially since the user may have written 5+3x, which is right, too, although it is preferred to write the other way around.

I sometimes have to check more complicated expressions, like -3x^2+7x-15 or -2 sin (4x^2).

Right now I’m doing an equation solving exercise. There I have to check what the user wants to do to the equation, like +2x or /(-5).

Does anybody have better ideas than character by character?