Lately it seems like the market is hitting new highs almost every day. You may think stocks are starting to get really expensive -- and you'd be right. When the market gets frothy, it's important to think defensively. If the market were to correct, what types of stocks would be hurt the least? With a little planning and research, you can figure out how to buy stocks that can survive anything that happens in the market.

The best stocks for an inflated market
There are two questions to ask when looking for potential investments in a pricey market.

First, is the stock in a "recession-resistant" business? For example, people will always need to buy groceries, gasoline, and other essentials. Companies that produce "luxuries" like high-end smartphones or designer clothes tend not to fare as well when the market goes sour.

Second, does this company pay a good dividend, and does it have a history of increasing that dividend? Dividend stocks tend to outperform their non-dividend-paying rivals over the long run, and they tend to be less volatile. One recent study actually found that dividend stocks have outperformed non-payers over most 20-year periods in history and that stocks with higher yields generally perform best.

A substantial dividend also creates a "price floor" for a stock. Consider AT&T (T 2.00%), which pays an annual yield of about 5.1% at the current share price. Well, if the share price were to fall 15% in a bear market, AT&T's dividend yield would climb to more than 6%. This makes the stock a more attractive investment, especially considering AT&T's long track record of raising its dividend, so buyers would swoop in and support to the stock price.

How to find good ones
The first thing you should do is figure out which sectors won't get crushed during bad economic times. Some retailers do very well during bear markets, such as Wal-Mart and AutoZone, both of which dramatically outperformed the overall market during the 2008-2009 crash. From the beginning of 2008 through the lows of March 2009, the S&P 500 lost about 50% of its value. Meanwhile, Wal-Mart fell just 1%, while AutoZone gained about 40%, making it one of the best performers of those years.

Other good sectors to choose include energy companies (from utilities to gasoline), telecom companies like the aforementioned AT&T, and consumer-staples producers like Procter & Gamble. People still need electricity in their homes, gasoline in their cars, and a way to get in touch with others.

Once you have a good idea of the types of companies that make good defensive investments, check out the dividend histories. Specifically, how long has the company been paying dividends? Has the dividend been raised every year? If so, for how long? Has the company been forced to cut the dividend in difficult times?

A great place to start your search is this list of stocks with the longest streaks of dividend increases. In fact, some of these companies have increased their dividends for 50 years or more.

Turning to AT&T example again, consider that AT&T has increased its dividend for 29 consecutive years -- impressive, considering that time period includes two of the worst recessions in history. So not only does the company pay an excellent yield now, but it's likely the dividend will also grow over time.

If you buy $10,000 of AT&T stock right now, you can expect annual income of around $510 in the form of dividends. But since AT&T's dividend increases by about 4% per year on average, in 30 years your income could grow to about $1,660, and that doesn't include the compounding effect of reinvesting your dividends.

If AT&T's dividend grows by 4% every year, and you reinvest all of your dividends, you could be looking at an annual income stream of nearly $7,500 in 30 years if history is any indication of where the company is heading.

A great move in any market
Basically, buying solid dividend-growth stocks in industries that can survive or even thrive in any economic environment is the best ticket to long-term wealth. By using these simple guidelines, you can figure out how to buy stocks that will work for you no matter what the market does.

And when the market starts to get expensive, it's an excellent way to invest defensively while still making solid long-term moves for your future.