On a Necessary and Sufficient Condition for Regularity in Constrained Optimization