Confining quantum particles with a purely magnetic field