Its the law which is named "Mankeded" as the batsman is dismissed in this manner. named after Great Vinoo Manked.
As a godd sportsman the bowler should warn the batsman first time when he attempts to leave the crease before the bal is bowled. If he still does then you can get him out. You have to do it before your delivery stride, means when your back foot lands last time before the ball is bowled.