Yes you can purchase a home after having been foreclosed upon, however it may take a number of years to repair your credit before becoming eligible. The standard waiting period for a Fannie Mae loan is 7 years. However If the foreclosure was the result of a documented extenuating circumstances, (Extenuating circumstances are non-recurring events that are beyond your control that resulted in a sudden, significant and prolonged reduction in income, or a catastrophic increase in your financial obligations) then you may be eligible for a Fannie Mae loan in as little as three years. In addition, there are some banks, ie Private Lenders....that may be willing to provide you with a loan even sooner.... however typically will require a larger down payment at a less competitive rate.
Hope that helps!