This is valid for the moment due to any localized current distribution provided that the magnetic field is uniform. For non-uniform B the equation is also valid for the torque about the center of the magnetic dipole provided that the magnetic dipole is small enough.