This is called Kaplansky condition: For $A$ entire, $A$ is a UFD iff every nonzero prime ideal contains a nonzero prime element.
Here prime element means that $p \in A$ is prime iff $p$ is non-zero non-unit and $p\mid ab$ implies $p \mid a$ or $p\mid b$.
Where can I get the proof of this statement?
Kaplansky's book "Commutative Rings" has the appropriately correct statement in the first few pages.