If someone forgets his fast and has sex, is his fast valid?

Fast Invalidators
Sex
Sex Forgetting Fast
If someone forgets his fast and has sex, is his fast valid?
If he forgets that he is fasting and has sex, his fast is in order. However, as soon as he remembers, he should terminate it; otherwise his fast is not valid.
Source: Hadana adopted from the Istiftaat of the Grand Ayatollah Khamenei