I usually dread shopping in stores. Trying on clothes is tedious, and sometimes completing the actual purchase is, too. Retailers like to ask for all sorts of information as they’re ringing up your merchandise, like your e-mail address and ZIP code. I just want to pay and be on my way, and they give me the third degree.

I always decline to give my e-mail address, since the last thing I need is more promotions clogging my in-box. But I’m often puzzled about the ZIP code, since in some instances — when paying for gasoline at the pump, for instance— you must type in your ZIP code to complete the transaction. It’s a security feature to verify that you’re authorized to use the card, since a clerk isn’t physically examining it.

It turns out, though, that stores are asking you for marketing purposes — an issue that is starting to come to light in state courts. Stores want your ZIP code because, combined with your name from your credit card, they can use it to find out other information about you from commercial databases, like your full mailing address. They may even sell the information to data brokers, who sell it to other marketers.

The result can be unwanted catalogs and other junk mail. (To get a simple idea of the cumulative impact of each tidbit of information, try searching for your name alone on Google search, and then search again using your name and ZIP code, and see how much more data comes back. If you have an uncommon name — as I do — it’s eye opening.)

In March, the Massachusetts Supreme Judicial Court ruled that collecting ZIP codes for credit card purchases violates a state consumer protection law. The ruling stemmed from a lawsuit a shopper had initially filed in federal court against the craft chain Michaels Stores Inc. The plaintiff said that because she had mistakenly believed that the information was necessary to complete the sale, she provided her ZIP code upon request several times when shopping there. As a result, her complaint said, she received unsolicited phone calls and mailings.

“Armed with a consumer’s name and ZIP code, Michaels is capable of obtaining its customers’ complete mailing address by utilizing a ‘reverse phone book’ that matches names and ZIP code, which it does in order to increase profits through direct marketing, or it could sell its customers’ mailing addresses to third parties,” the plaintiff argued in a legal brief filed with the state court.

The court found that a ZIP code was “personal identification information” because when combined with the consumer’s name, it provided enough information to identify the consumer’s address or telephone number.

A Michaels spokesman didn’t respond to a request for comment.

The case is similar to one in California in 2011, in which the state’s Supreme Court ruled that ZIP codes qualified as personal information under a state credit card privacy law. About a dozen other states have similar laws but so far they haven’t been interpreted in the same way, retail lawyers say.

The Massachusetts case is leading to suits against other stores, as happened in California.

So what should you do if you’re asked for your ZIP code at checkout?

Gregory Parks, a lawyer who represents big merchants as head of the retail litigation practice group at Morgan Lewis in Philadelphia, said most stores won’t insist that you give your ZIP code. So if you don’t want to provide it, you should just politely decline. “If you prefer not to give it, they’ll process the sale anyway,” he said.

But all stores are still entitled to ask for the information, he said, if it is required to complete a transaction. One example, he said, is if you hand over your credit card to the clerk but for some reason it won’t swipe properly. The store needs extra information to verify that you are authorized to use the card.

(American Express gives merchants the option of a using a system in which shoppers must provide their ZIP code, to match with the billing ZIP code on file, as an antifraud mechanism. Generally, an American Express spokeswoman said, merchants are restricted from using or storing information about the cardholder for other purposes.)

Mr. Parks also said that the court’s restriction didn’t apply to cash transactions. Stores seek ZIP code information to better identify where their customers are located, which helps in selecting sites for new stores, and to make sure that stores have the products that customers in that area want. “They want to improve customer service and have stuff you want to buy,” he said. Providing the information is still optional. But since you’re not providing a credit card with your name on it, it’s unlikely to lead to unwanted solicitations.

Mallory Duncan, general counsel for the National Retail Federation, said consumers needn’t give their ZIP code if they would rather not, but they may do themselves a disservice by withholding it. “I guess the question is, what is the perceived harm you’re trying to protect against?” he said. “A better selection in the stores? That’s an odd harm to be protecting against.”

Nancy Perkins, a lawyer with Arnold & Porter in Washington, D.C., who specializes in data privacy, said customers can simply ask if the information is necessary to complete the transaction.

Paul Stephens, director of policy and advocacy for the Privacy Rights Clearinghouse, suggested that if you would rather not get into a possible debate with a store clerk — or if, for some reason, the cashier doesn’t know how to finish the transaction without a ZIP code — that you simply give an incorrect one. Or, “Make one up.”

What do you do if you’re asked for your ZIP code or other information when shopping?