Contracts can be entire or severable.
A court may enforce an entire contract or void it. However, a court may also remove certain provisions of a contract and leave the rest intact. It is important to keep this in mind when drafting contracts. If appropriate, the contract should contain a clause that indicates that it is the intent of the parties to keeps as much of the contract intact.