Praise be to Allah.Praise be to Allaah.
Yes, the prayer is valid, but it is better to appoint as your imaam the one who reads the Qur’aan best, and who has the best understanding of Islam. That is better, because the Prophet (peace and blessings of Allaah be upon him) said: “Let the people appoint as their imaam the one amongst them who reads the Qur’aan best.” (Narrated by Muslim, no. 673). The meaning of the one who reads the Qur’aan best is the one who reads it and acts in accordance with it, because there is nothing good in reading it and not acting in accordance with it. If the people appoint a person to be the imaam, and among the congregation there is someone who reads the Qur’aan better than he does, that is not right, as implied in the hadeeth.
Imaam Ahmad mentioned in his book Risaalat al-Sunniyah: If a person leads people in prayer and among them there is someone who is better than him, they will be in a state of decline. So it is better for you to be led in prayer by the one who is most pious, who has the best understanding of Islam and who has the most knowledge of the Qur’aan. But if we suppose that this man who smokes cigarettes or who shaves his beard or who smokes the narghile or who grows his hair long comes forward and leads you in prayer, we say: the prayer is valid, and you do not need to repeat it, because he is Muslim, but the prayer is imperfect.
And Allaah knows best.