If Donald Trump were to challenge the outcome of next month's presidential election, as he has hinted he might, he would face a difficult and expensive fight, according to election attorneys and a review of voting laws in key battleground states.

Trump has said he is worried the Nov. 8 election might be rigged in favor of his opponent, Hillary Clinton, and in Wednesday's debate he refused to say he would accept the outcome.

But before any court challenge, Trump probably would have to ask for a recount, said Donald Brey, a Republican election lawyer in Ohio. If the campaign did not pursue out-of-court options first, he said, a judge likely would dismiss the case.

Recount rules vary from state to state. North Carolina, for example, doesn't allow a presidential candidate to request a recount at all if one candidate has a lead of more than 0.5 percent of the total votes cast.

In Wisconsin, the challenging candidate must pay the full expense of a recount if the vote in dispute is more than 0.25 percent, and in Colorado if it is more than 0.5 percent.

That can be expensive. Officials in one Wisconsin village put the cost of a local recount, in which about 9,000 votes were cast earlier this year, at nearly $13,000, said Michael Maistelman, a Wisconsin election lawyer who represented the unsuccessful candidate. More than 3 million people voted in the 2012 presidential election in Wisconsin.

Deciding where to challenge the election would be complicated. Trump, who trailed Clinton by 7 percentage points nationwide in a Reuters/Ipsos poll released last week, is fighting tight battles in some key states. In Ohio, for example, an average of major opinion polls reviewed by the RealClearPolitics website found Trump to be leading by less than 1 percentage point. In Iowa, he is leading by nearly 4 percent.

In some other battleground states, polls suggest support for Trump has eroded in recent weeks. According to the RealClearPolitics website's poll tally, Clinton has substantial leads in Virginia, Colorado and Wisconsin. She leads Trump by more than 6 percentage points in Pennsylvania, nearly 4 points in Florida and more than two points in North Carolina.

To maximize his chances of overturning a Clinton win, Trump might need to challenge the results in several states, said Troy McCurry, a former Republican National Committee lawyer who was part of the party's recount team in 2012.

Trump could try to bring a legal claim without first asking for recount by alleging, for instance, that an abuse of power by an election official, said McCurry, who's law firm represented Ted Cruz in the Republican primary before McCurry joined the practice.

But if Trump's lawyers were unable to muster specific facts to support that premise, he said, a judge would dismiss the lawsuit.

Any lawsuit that withstood early challenges would face an uncertain future. With the U.S. Supreme Court split 4-to-4 between liberal and conservative justices, state supreme courts or federal appeals courts could well make the final ruling in any election dispute.

In Pennsylvania, Colorado and Florida, where a majority of both state and federal appeals court judges have Democratic affiliations, Trump might face a more difficult road.

Meanwhile, appeals courts in Ohio, Wisconsin and Iowa are more heavily Republican.

Ohio election attorney Brey, who said he dislikes but will vote for Trump, believes a challenge in Ohio would be a last-ditch effort for the candidate.

"Let's put it this way," he said. "If Ohio is close, Trump's already lost."

Trump also might face obstacles from his own party, attorneys said, because it would be reluctant to challenge results in a state where, say, it lost the presidential race but won a close U.S. senate race.

Numerous studies have shown U.S. elections, which are decentralized and run by the states, are basically sound.

"Mr. Trump never mentions what criteria would be necessary for him to make a decision about a challenge," said Stephen Zack, an attorney who represented Vice President Al Gore in the case that was brought to the Supreme Court over the election recount in Florida in 2000.

"Basically it is left as, 'I'll see what it smells like and then I will surprise you,'" Zack said. "There are rule-of-law issues that pertain to elections that separate us from anywhere else in the world."  

Election officials in several states rejected suggestions the balloting might be rigged. Eric Spencer, election director in Arizona, said that while isolated incidents of voter fraud might occur and should be investigated, election workers come from all political parties and work with integrity.

"The notion that the election is rigged is preposterous if not insulting," Spencer said.

Some election watchers question how serious Trump is about a challenge.

"A lot of this is just posturing," McCurry said. "At the end of the day I don't see how this happens."