All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
It is obligatory upon a Muslim to keep away from mixing with women as much as he can for this implies many evils that are mostly likely to occur. Rather, their occurrence may be certain. This actually differs from one person to another and from one place to another. Whoever is afflicted with such a thing without seeking it or willful intention on his part has to restrict himself against prohibited looking and unnecessary speech with women. This is purer to his heart, more diminishing for his desires, and more protective for his religion. If he fasts, then his fast is valid. That is because being with women in the same place is not one of the matters that break the fast.
Allaah Knows best.