It is legal to resign with immediate effect if you have worked somewhere for less than a month and have no contract. Otherwise, you are bound by the terms of your contract.