Hazrat Imam Mahdi (as) bears the special characteristics and more from the previous prophets. He is the embodiment of their virtues and qualities. He carries their signs and is the inheritor of all that they stood for and what was revealed upon them. The following article mentions the similarity between Hazrat Yahya (as) and Imam Mahdi (as).
Prophecy regarding his birth
Prophecy and glad tidings regarding Yahya (as) were received before he was born. In the case of Imam Mahdi (as) also prophecy and glad tidings arrived before his birth.
Speaking from the womb
Hazrat Yahya (as) spoke to his mother while he was yet in the womb as mentioned in the tradition of Imam Hasan Askari (as) when he said: “One day Maryam came to the mother of Yahya – the wife of Zakariya – but she did not stand up for her. Yahya [in the mother’s womb] called out: Will you not stand up for the best woman of the world who has come to you carrying the best of the men? Thus his mother felt ashamed and stood up.” (Beharul Anwar volume 14, page 187)
Imam Mahdi (as) also, as mentioned in the report of Janabe Hakima, spoke while he was in the womb of the mother and he recited Surah Qadr. (Kamaluddin, volume 2, page 428)
Piety and more
Yahya (as) was the most pious and devout person of his time. Qaim (as) also is the most pious and devout person of his time.
(The above article was taken and adapted from the book Mikyalul Makarim Fee Fawaedid Dua Lil Qaem)