You can't trust that the user has JavaScript enabled; and since you can't trust user input anyway, you'd have to do this server side.
If your code cares about unicode spaces at the beginning of user input, there is your problem.
(Also, you missed the reject part)