To prevent constipation you should eat 18g of fiber a day.
The following foods are rich in fiber;
A high fiber diet keeps your bowel healthy and allows waste products to pass out of your body. Fiber rich food keeps you satisfied, preventing hunger pangs, frequent snacking and overeating.
In addition to the above you need to drink adequate fluids. At least two liters of water a day and exercise regularly.
Despite having adequate fiber, fluids and exercise, some people may still have constipation. If that is the case consult your health care provider whom I am sure will make the appropriate recommendations.