In this article we discuss generalized harmonic confinement of massless Dirac fermions in (2+1) dimensions using smooth finite magnetic fields. It is shown that these types of magnetic fields lead to conditional confinement, that is confinement is possible only when the angular momentum (and parameters which depend on it) assumes some specific values. The solutions for non zero energy states as well as zero energy states have been found exactly.