A woman with istihaadah (irregular bleeding) who had a regular cycle should stop praying at the time when she used to get her menses, whether at the beginning of the month, in the middle or at the end
Question

                My period has been irregular for more than two years. I get it for seven days three months in a row. I am not married. Seven months ago, my period started to come once every two months. I used a folk remedy three months ago, and my period started to last for ten or fifteen days, so I started to regard the first seven days as hayd (menses) and the rest as istihaadah (irregular bleeding). My period came on 16 Sha‘baan as usual, and as usual I regarded the first seven days as menses and the rest as istihaadah. On 27 Sha‘baan, I took pills to stop the period, and the bleeding stopped for four days. I did ‘umrah in Makkah on 2 Ramadan, and because of the physical exertion and walking, my period started again, even though I did not stop taking the pills. Even though I saw the blood, I carried on fasting and praying in the Haram in Makkah until 14 Ramadan, when the bleeding stopped. Are my prayers and fasting valid?
Praise be to Allah.Firstly:
The basic principle regarding the bleeding experienced by women is that it is menses (hayd), so long as it does not last for longer than fifteen days, in which case it is regarded as istihaadah (irregular bleeding) by the majority of scholars.
Some of the scholars – including Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) – are of the view that a woman is not mustahaadah (experiencing irregular bleeding) unless the bleeding lasts all month, or for most of the month.
According to the majority view, if your bleeding lasts for more than fifteen days, then anything over fifteen days is istihaadah, and in the following month you should stop praying etc. for the length of your regular cycle, which is seven days – if that was the length of your last period before the occurrence of istihaadah – then after that you should do ghusl [and resume praying etc.].
If your period used to come in the middle of the month, then you should stop praying etc. in the middle of the month.
It says in Mataalib Ooli an-Nuha (1/255-257):
If a woman who has a regular cycle experiences istihaadah, if she knows her regular cycle, the time when her menses begins and ends, and how many days it lasts, then she should stop praying etc. at that time, even if the blood looks different.
And her cycle is the duration of her menses and the duration of the time when she is “pure” (i.e., not menstruating), such as fourteen days of menses, or one day and one night, which is the minimum duration thereof, and thirteen days for the time when she is “pure”, which is the minimum duration thereof.
The second scenario is when she remembers how many days her menses usually lasted, but she has forgotten when in the (lunar) month it used to occur, but she thinks it was probably the second half of the month. In that case she should count the same number of days for her menses from when she realises her menses has started.
If she does not know how long her period lasts,  because she does not know whether her menses used to come at the beginning of the month, in the middle or at the end, then she should start counting her menses from the beginning of each lunar month, on the basis that this is most likely to be the case. End quote.
Therefore, the bleeding that occurred on the second day of Ramadan was not hayd (menses), for two reasons:
Firstly: because your period comes in the middle of the month, not at the beginning.
Secondly: because there was no interval of thirteen days between it and the period that came before it, which is the minimum duration of purity between two menses.
So you did well by praying and fasting during these days.
Secondly:
If the bleeding did not last for longer than fifteen days, then you were not mustahaadah.
Assuming that this is the case, the bleeding that occurred on the second day of Ramadan was not menses, because there was no interval of thirteen days between it and the period that came before it. So your prayer and fasting are valid.
And Allah knows best.