It is narrated from Hazrat Mu'adh (may Allah be pleased with him) that a man came to the service of the Noble Prophet (peace and blessings be upon him) and said, "O Messenger of Allah! What do you say about a man who meets a strange woman and does with her everything that a man does with his wife, except intercourse?" Upon this, Allah the Exalted revealed this verse: "Establish prayer at the two ends of the day and at some hours of the night; indeed, good deeds erase bad deeds." The Noble Prophet (peace and blessings be upon him) said to that person, "Perform ablution and offer prayer." I asked, "O Messenger of Allah! Is this command specific to him or general for all Muslims?" The Noble Prophet (peace and blessings be upon him) said, "It is general for all Muslims."
Hadith Referenceمسند احمد / مسند الأنصار رضي الله عنهم / 22112
Hadith Gradingحکم دارالسلام:صحيح لغيره، وهذا إسناد منقطع، عبدالرحمن بن أبى ليلى لم يسمع معاذا