Praise be to Allah.
Zina: A Grave sin in Islam
Zina (fornication, adultery) is a serious crime and a major sin which takes away the quality of faith from a person, and exposes him to punishment and humiliation unless he repents. Allah says (interpretation of the meaning):
“And come not near to unlawful sex. Verily, it is a Fahishah (i.e. anything that transgresses its limits: a great sin, and an evil way that leads one to hell unless Allah Forgives him).” [al-Isra 17:32]
And the Prophet (peace and blessings of Allah be upon him) said: “No adulterer is a believer at the time when he is committing adultery” Narrated by al-Bukhari (2475) and Muslim (57).
And he (peace and blessings of Allah be upon him) said: “If a man commits zina, faith comes out of him and hovers over him like a cloud, then when he stops, faith returns to him.” (Narrated by Abu Dawud (4960) and al-Tirmidhi (2625); classed as sahih by al-Albani in Sahih Abi Dawud.)
Punishment for zina
The Prophet (peace and blessings of Allah be upon him) has told us of the punishment that those who commit zina will receive in their graves before the Hour begins, and that they will be punished with fire. Narrated by al-Bukhari (1320).
Because of the abhorrent nature of this crime, Allah has decreed that the punishment for it should be stoning to death if the person is married and flogging if he was not married.
The one who is faced with any such thing should hasten to repent to Allah and do a lot of good deeds, in the hope that Allah will forgive him. Allah says (interpretation of the meaning):
“And those who invoke not any other ilah (god) along with Allah, nor kill such person as Allah has forbidden, except for just cause, nor commit illegal sexual intercourse and whoever does this shall receive the punishment. The torment will be doubled to him on the Day of Resurrection, and he will abide therein in disgrace. Except those who repent and believe (in Islamic Monotheism), and do righteous deeds; for those, Allah will change their sins into good deeds, and Allah is Oft-Forgiving, Most Merciful.” [al-Furqan 25:68-70]
“And verily, I am indeed forgiving to him who repents, believes (in My Oneness, and associates none in worship with Me) and does righteous good deeds, and then remains constant in doing them (till his death).” [Ta-Ha 20:82]
They must also conceal themselves with the concealment of Allah, and not tell anyone about that. The Prophet (peace and blessings of Allah be upon him) said: “Avoid these filthy things that Allah has forbidden. Whoever has done any of them, let him conceal himself with the concealment of Allah, may He be glorified and exalted.” (Narrated by al-Bayhaqi and classed as sahih by al-Albani in al-Silsilah al-Sahihah, no. 663.)
Can you marry someone you committed zina with?
It is not permissible for a man or woman who has committed zina to get married until after he or she has repented , because Allah says (interpretation of the meaning):
“The adulterer — fornicator marries not but an adulteress — fornicatress or a Mushrikah; and the adulteress –fornicatress, none marries her except an adulterer — fornicater or a Mushrik [and that means that the man who agrees to marry (have a sexual relation with) a Mushrikah (female polytheist, pagan or idolatress) or a prostitute, then surely, he is either an adulterer — fornicator, or a Mushrik (polytheist, pagan or idolater). And the woman who agrees to marry (have a sexual relation with) a Mushrik (polytheist, pagan or idolater) or an adulterer — fornicator, then she is either a prostitute or a Mushrikah (female polytheist, pagan, or idolatress)]. Such a thing is forbidden to the believers (of Islamic Monotheism).” [al-Nur 24:3]
Had sex before marriage: Is marriage valid?
If they had both repented to Allah before getting married, and they regretted the haram things that they had done, then their marriage is valid. But if they did the marriage contract before they repented, then the marriage is not valid and they have to repent to Allah and regret what they have done, and resolve not to do such a thing again, then they should make a new marriage contract.
And Allah knows best.