Movment limitationson a quad

I want to limit the movment of an object to the area of a quad. How in hell do I do this as simple as possible?
Some sort of code example is prefered.