Prophet Muhammad (peace and blessings be upon him) is reported to have recommended fasting during the four sacred months (i.e. Dhul-Qi`dah, Dhul-Hijjah, Muharram, and Rajab). Therefore, a Muslim is generally recommended to observe fasting in these sacred months, and Rajab is one of them. It is also reported that the Prophet (peace and blessings be upon him) used to observe fasting in Sha`ban more than he did in other months.
In response to the topic, prominent Muslim scholar Dr. Muhammad Ahmad Al-Musayyar, professor of Islamic creed and philosophy at Al-Azhar University, stated,
Fasting is a spiritual act of worship, which elevates one to the rank of angels, as one abstains from eating, drinking, and sexual relations from dawn until sunset.
In general, a Muslim should fast some days every now and then; in these days, one abstains from worldly matters, strengthens his or her resolution, and purifies his or her soul.
However, no authentic hadiths are stated indicating that the Prophet (peace and blessings be upon him) recommended fasting in the month of Rajab, nor did he forbid fasting in it, according to Imam An-Nawawi, who added that fasting in general is recommended.
Still, it is recorded in Sunan Abu Dawud that Allah’s Messenger (peace and blessings be upon him) recommended fasting during the Four Sacred Months, among which is the month of Rajab.
As for the month of Sha`ban, there are authentic hadiths about the virtue of fasting during it, among which the hadith recorded in Sahih Muslim on the authority of `A’ishah who said, “Allah’s Messenger (peace and blessings be upon him) used to observe fasting (continuously) that we would say he would not break fasting, and he used not to fast (continuously) until we would say he would not fast. And I did not see Allah’s Messenger (peace and blessings be upon him) completing the fast of a month, except Ramadan, and I did not see him fasting more in any other month than in Sha`ban.
The hadith indicates that the Messenger (peace and blessings be upon him) used to fast many days in Sha`ban that `A’ishah said in another narration, “He [the Prophet] used to fast (almost) all of Sha`ban; he used to fast Sha`ban except for few (days).”
Except for these two months, Allah’s Messenger (peace and blessings be upon him) used to observe fasting continuously to the extent that people would say that he would not break fasting.
He also used to keep breaking the fast for many consecutive days to the extent that people would say that he would not fast.
So the matter depends on feeling comfortable and devoted to worship without feeling bored or weary. That is why the Prophet (peace and blessings be upon him) said, “Do (good) deeds that are within your capacity, as Allah never gets tired of giving rewards until you get tired of doing good deeds.”
He (peace and blessings be upon him) also said, “The most beloved deed to Allah is the one its doer performs regularly even if it were little.”