How do you know the valence of a non-metal?

The number of electrons gained by a non-metal element for its atom to attain owe configuration is its valency, which is equal to 8 - its group number. Eg The valency of chlorine is (8 - 7) = 1