The valency of an elements is determined by the number of valence electrons present in the outer shell of an atom. Since all the elements of a group have the same number of valence electrons. Therefore, they have same valency.
For example, alkali metals have one valence electron. Hence, their valence is 1. Similarly, alkaline earth metals have two valence electrons. Hence, their valence is 2.