Whoever masturbates during the day in Ramadan has to repent to Allah and refrain from eating and drinking for the rest of the day, and he has to make up that fast later on.
If he starts to masturbate then stops without ejaculating, he has to repent, but his fast is still valid, and he does not have to make it up later because he did not ejaculate. The fasting person should keep away from everything that provokes desire and shun bad thoughts.
Ref: Islamqa.info
Masturbation is haraam( forbidden and lawful).