The Prophet said, "If somebody eats or drinks forgetfully then he should complete his fast, for what he has eaten or drunk, has been given to him by God."
Islam has as one of its "five pillars" the practice of Sawm, which is not merely fasting from all food and drink (including water), but equally from impure thoughts, words and deeds.
Specific occasions (most notably daytime fasting (see sawm) and menstruation) are times forbidden for intercourse, though not for other ways of touching and being close to one another.