Praise be to Allah.
It is haraam for a man to touch the hand of a girl who is not his mahram, because the Prophet (peace and blessings of Allaah be upon him) said: “For one of you to be stabbed in the head with an iron needle is better for him than for him to touch a woman who is not permissible for him.” Narrated by al-Tabaraani from the hadeeth of Ma’qil ibn Yasaar (may Allaah have mercy on him); classed as saheeh by al-Albaani in Saheeh al-Jaami’, 5045.
If this applies to mere touching, then hugging and kissing are even more serious matters. If the woman tries to do that, the man must stop her, and not allow her to do something haraam with him.
This is a general ruling which applies to the one who is fasting and to others. But if a person is fasting it is even more important that he keep away from all haraam things and all things that can provoke desire, which go against the wisdom and aims of fasting. Allaah says, explaining the reason why fasting has been enjoined (interpretation of the meaning):
“O you who believe! Observing As-Sawm (the fasting) is prescribed for you as it was prescribed for those before you, that you may become Al-Muttaqoon (the pious)”
And Allaah says in a hadeeth qudsi: “Fasting is for Me and I will reward for it. He gives up his desire and his food and drink for My sake.” Narrated by al-Bukhaari, 7492; Muslim, 1151.
The one who has done that must repent to Allaah and resolve never to do it again.
With regard to his fast, that is subject to further discussion:
If semen (maniy) came out of him because of this action, then his fast is invalidated and he must make up that day. If no semen came out of him, then his fast is still valid.
But the fact that his fast is still valid does not mean that there is no sin on him or that his fast is perfect. Not at all. Rather every sin that a person commits detracts from the reward of his fast, and may cancel out the reward altogether.
The Prophet (peace and blessings of Allaah be upon him) said: “Whoever does not give up false speech and false actions and ignorance, Allaah has no need of his giving up his food and drink.” Narrated by al-Bukhaari, 6057.
He also (peace and blessings of Allaah be upon him) said: “A fasting person may get nothing from his fast except hunger and the one who prays at night may get nothing from his qiyaam but a sleepless night.” Narrated by Ibn Maajah, 1690; classed as saheeh by al-Albaani in Saheeh Ibn Maajah.
See also question no. 50063
We ask Allaah to set our affairs straight and to protect us from temptation.
And Allaah knows best.